You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/develop/clients/nodejs/error-handling.md
+27-2Lines changed: 27 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: Error handling
3
3
description: Learn how to handle errors when using node-redis.
4
4
linkTitle: Error handling
5
-
weight: 50
5
+
weight: 6
6
6
---
7
7
8
8
node-redis uses
@@ -63,6 +63,27 @@ client.get(key)
63
63
});
64
64
```
65
65
66
+
## Error events
67
+
68
+
Node-Redis provides [multiple events to handle various scenarios](https://github.com/redis/node-redis?tab=readme-ov-file#events), among which the most critical is the `error` event.
69
+
70
+
This event is triggered whenever an error occurs within the client.
71
+
72
+
It is crucial to listen for error events.
73
+
74
+
If a client does not register at least one error listener and an error occurs, the system will throw that error, potentially causing the Node.js process to exit unexpectedly.
75
+
See [the EventEmitter docs](https://nodejs.org/api/events.html#events_error_events) for more details.
76
+
77
+
```typescript
78
+
const client =createClient({
79
+
// ... client options
80
+
});
81
+
// Always ensure there's a listener for errors in the client to prevent process crashes due to unhandled errors
82
+
client.on('error', error=> {
83
+
console.error(`Redis client error:`, error);
84
+
});
85
+
```
86
+
66
87
## Applying error handling patterns
67
88
68
89
The [Error handling]({{< relref "/develop/clients/error-handling" >}})
Copy file name to clipboardExpand all lines: content/develop/clients/nodejs/produsage.md
+5-19Lines changed: 5 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ categories:
12
12
description: Get your Node.js app ready for production
13
13
linkTitle: Production usage
14
14
title: Production usage
15
-
weight: 5
15
+
weight: 8
16
16
---
17
17
18
18
This guide offers recommendations to get the best reliability and
@@ -38,24 +38,10 @@ progress in implementing the recommendations.
38
38
39
39
Node-Redis provides [multiple events to handle various scenarios](https://github.com/redis/node-redis?tab=readme-ov-file#events), among which the most critical is the `error` event.
40
40
41
-
This event is triggered whenever an error occurs within the client.
42
-
43
-
It is crucial to listen for error events.
44
-
45
-
If a client does not register at least one error listener and an error occurs, the system will throw that error, potentially causing the Node.js process to exit unexpectedly.
46
-
See [the EventEmitter docs](https://nodejs.org/api/events.html#events_error_events) for more details.
47
-
48
-
```typescript
49
-
const client =createClient({
50
-
// ... client options
51
-
});
52
-
// Always ensure there's a listener for errors in the client to prevent process crashes due to unhandled errors
53
-
client.on('error', error=> {
54
-
console.error(`Redis client error:`, error);
55
-
});
56
-
```
57
-
58
-
See also [Error handling]({{< relref "/develop/clients/nodejs/error-handling" >}}) for a more detailed discussion of error handling approaches in `node-redis`.
41
+
This event is triggered whenever an error occurs within the client, and
42
+
it is very important to set a handler to listen for it.
43
+
See [Error events]({{< relref "/develop/clients/nodejs/error-handling#error-events" >}})
44
+
for more information and an example of setting an error handler.
0 commit comments