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
For a list of Redis commands, see [Redis Command Reference](http://redis.io/commands)
113
113
114
-
The commands can be specified in uppercase or lowercase for convenience. `client.get()` is the same as `client.GET()`.
115
-
116
114
Minimal parsing is done on the replies. Commands that return a integer return JavaScript Numbers, arrays return JavaScript Array. `HGETALL` returns an Object keyed by the hash keys. All strings will either be returned as string or as buffer depending on your setting.
117
115
Please be aware that sending null, undefined and Boolean values will result in the value coerced to a string!
118
116
@@ -139,6 +137,7 @@ are passed an object containing `delay` (in ms) and `attempt` (the attempt #) at
139
137
### "error"
140
138
141
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.
142
141
143
142
So please attach the error listener to node_redis.
144
143
@@ -182,7 +181,7 @@ __Tip:__ If the Redis server runs on the same machine as the client consider usi
182
181
| host | 127.0.0.1 | IP address of the Redis server |
183
182
| port | 6379 | Port of the Redis server |
184
183
| path | null | The UNIX socket string of the Redis server |
185
-
| url | null | The URL of the Redis server. Format: `[redis:]//[user][:password@][host][:port][/db-number][?db=db-number[&password=bar[&option=value]]]` (More info avaliable at [IANA](http://www.iana.org/assignments/uri-schemes/prov/redis)). |
184
+
| url | null | The URL of the Redis server. Format: `[redis:]//[[user][:password@]][host][:port][/db-number][?db=db-number[&password=bar[&option=value]]]` (More info avaliable at [IANA](http://www.iana.org/assignments/uri-schemes/prov/redis)). |
186
185
| parser | hiredis | If hiredis is not installed, automatic fallback to the built-in javascript parser |
187
186
| string_numbers | null | Set to `true`, `node_redis` will return Redis number values as Strings instead of javascript Numbers. Useful if you need to handle big numbers (above `Number.MAX_SAFE_INTEGER === 2^53`). Hiredis is incapable of this behavior, so setting this option to `true` will result in the built-in javascript parser being used no matter the value of the `parser` option. |
188
187
| return_buffers | false | If set to `true`, then all replies will be sent to callbacks as Buffers instead of Strings. |
@@ -295,6 +294,51 @@ client.get("foo_rand000000000000", function (err, reply) {
295
294
296
295
`client.end()` without the flush parameter set to true should NOT be used in production!
297
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
+
redis.debug_mode=false;
328
+
});
329
+
});
330
+
331
+
```
332
+
333
+
Every `ReplyError` contains the `command` name in all-caps and the arguments (`args`).
334
+
335
+
If node_redis emits a library error because of another error, the triggering error is added to the returned error as `origin` attribute.
336
+
337
+
___Error codes___
338
+
339
+
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.
340
+
A `CONNECTION_BROKEN` error code is used in case node_redis gives up to reconnect.
341
+
298
342
## client.unref()
299
343
300
344
Call `unref()` on the underlying socket connection to the Redis server, allowing the program to exit once no more commands are pending.
@@ -363,7 +407,7 @@ client.HMSET(key1, "0123456789", "abcdefghij", "some manner of key", "a type of
363
407
364
408
## Publish / Subscribe
365
409
366
-
Here is a simple example of the API for publish / subscribe. This program opens two
410
+
Example of the publish / subscribe API. This program opens two
367
411
client connections, subscribes to a channel on one of them, and publishes to that
368
412
channel on the other:
369
413
@@ -412,6 +456,16 @@ Client will emit `pmessage` for every message received that matches an active su
412
456
Listeners are passed the original pattern used with `PSUBSCRIBE` as `pattern`, the sending channel
413
457
name as `channel`, and the message as `message`.
414
458
459
+
### "message_buffer" (channel, message)
460
+
461
+
This is the same as the `message` event with the exception, that it is always going to emit a buffer.
462
+
If you listen to the `message` event at the same time as the `message_buffer`, it is always going to emit a string.
463
+
464
+
### "pmessage_buffer" (pattern, channel, message)
465
+
466
+
This is the same as the `pmessage` event with the exception, that it is always going to emit a buffer.
467
+
If you listen to the `pmessage` event at the same time as the `pmessage_buffer`, it is always going to emit a string.
468
+
415
469
### "subscribe" (channel, count)
416
470
417
471
Client will emit `subscribe` in response to a `SUBSCRIBE` command. Listeners are passed the
@@ -529,7 +583,7 @@ Redis. The interface in `node_redis` is to return an individual `Batch` object b
529
583
The only difference between .batch and .multi is that no transaction is going to be used.
530
584
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.
531
585
532
-
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.
586
+
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.
533
587
534
588
## Monitor mode
535
589
@@ -539,7 +593,7 @@ across all client connections, including from other client libraries and other c
539
593
A `monitor` event is going to be emitted for every command fired from any client connected to the server including the monitoring client itself.
540
594
The callback for the `monitor` event takes a timestamp from the Redis server, an array of command arguments and the raw monitoring string.
541
595
542
-
Here is a simple example:
596
+
Example:
543
597
544
598
```js
545
599
var client =require("redis").createClient();
@@ -599,9 +653,10 @@ the second word as first parameter:
Duplicate all current options and return a new redisClient instance. All options passed to the duplicate function are going to replace the original option.
659
+
If you pass a callback, duplicate is going to wait until the client is ready and returns it in the callback. If an error occurs in the meanwhile, that is going to return an error instead in the callback.
@@ -615,27 +670,16 @@ All commands are sent as multi-bulk commands. `args` can either be an Array of a
615
670
616
671
Boolean tracking the state of the connection to the Redis server.
617
672
618
-
## client.command_queue.length
673
+
## client.command_queue_length
619
674
620
675
The number of commands that have been sent to the Redis server but not yet replied to. You can use this to
621
676
enforce some kind of maximum queue depth for commands while connected.
622
677
623
-
Don't mess with `client.command_queue` though unless you really know what you are doing.
624
-
625
-
## client.offline_queue.length
678
+
## client.offline_queue_length
626
679
627
680
The number of commands that have been queued up for a future connection. You can use this to enforce
628
681
some kind of maximum queue depth for pre-connection commands.
629
682
630
-
## client.retry_delay
631
-
632
-
Current delay in milliseconds before a connection retry will be attempted. This starts at `200`.
633
-
634
-
## client.retry_backoff
635
-
636
-
Multiplier for future retry timeouts. This should be larger than 1 to add more time between retries.
637
-
Defaults to 1.7. The default initial connection retry is 200, so the second retry will be 340, followed by 578, etc.
638
-
639
683
### Commands with Optional and Keyword arguments
640
684
641
685
This applies to anything that uses an optional `[WITHSCORES]` or `[LIMIT offset count]` in the [redis.io/commands](http://redis.io/commands) documentation.
0 commit comments