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: README.md
+46-1Lines changed: 46 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -137,6 +137,7 @@ are passed an object containing `delay` (in ms) and `attempt` (the attempt #) at
137
137
### "error"
138
138
139
139
`client` will emit `error` when encountering an error connecting to the Redis server or when any other in node_redis occurs.
140
+
If you use a command without callback and encounter a ReplyError it is going to be emitted to the error listener.
140
141
141
142
So please attach the error listener to node_redis.
142
143
@@ -293,6 +294,50 @@ client.get("foo_rand000000000000", function (err, reply) {
293
294
294
295
`client.end()` without the flush parameter set to true should NOT be used in production!
295
296
297
+
## Error handling (>= v.2.6)
298
+
299
+
All redis errors are returned as `ReplyError`.
300
+
All unresolved commands that get rejected due to what ever reason return a `AbortError`.
301
+
As subclass of the `AbortError` a `AggregateError` exists. This is emitted in case multiple unresolved commands without callback got rejected in debug_mode.
302
+
They are all aggregated and a single error is emitted in that case.
303
+
304
+
Example:
305
+
```js
306
+
var redis =require('./');
307
+
var assert =require('assert');
308
+
var client =redis.createClient();
309
+
310
+
client.on('error', function (err) {
311
+
assert(err instanceofError);
312
+
assert(err instanceofredis.AbortError);
313
+
assert(err instanceofredis.AggregateError);
314
+
assert.strictEqual(err.errors.length, 2); // The set and get got aggregated in here
315
+
assert.strictEqual(err.code, 'NR_CLOSED');
316
+
});
317
+
client.set('foo', 123, 'bar', function (err, res) { // To many arguments
client.end(true); // Force closing the connection while the command did not yet return
327
+
});
328
+
});
329
+
330
+
```
331
+
332
+
Every `ReplyError` contains the `command` name in all-caps and the arguments (`args`).
333
+
334
+
If node_redis emits a library error because of another error, the triggering error is added to the returned error as `origin` attribute.
335
+
336
+
___Error codes___
337
+
338
+
node_redis returns a `NR_CLOSED` error code if the clients connection dropped. If a command unresolved command got rejected a `UNERCTAIN_STATE` code is returned.
339
+
A `CONNECTION_BROKEN` error code is used in case node_redis gives up to reconnect.
340
+
296
341
## client.unref()
297
342
298
343
Call `unref()` on the underlying socket connection to the Redis server, allowing the program to exit once no more commands are pending.
@@ -537,7 +582,7 @@ Redis. The interface in `node_redis` is to return an individual `Batch` object b
537
582
The only difference between .batch and .multi is that no transaction is going to be used.
538
583
Be aware that the errors are - just like in multi statements - in the result. Otherwise both, errors and results could be returned at the same time.
539
584
540
-
If you fire many commands at once this is going to **boost the execution speed by up to 400%**[sic!] compared to fireing the same commands in a loop without waiting for the result! See the benchmarks for further comparison. Please remember that all commands are kept in memory until they are fired.
585
+
If you fire many commands at once this is going to boost the execution speed significantly compared to fireing the same commands in a loop without waiting for the result! See the benchmarks for further comparison. Please remember that all commands are kept in memory until they are fired.
0 commit comments