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
If the key is missing, reply will be null (probably):
85
+
If the key is missing, reply will be null. Only if the [Redis Command Reference](http://redis.io/commands) states something else it will not be null.
82
86
83
87
```js
84
88
client.get("missingkey", function(err, reply) {
@@ -103,15 +107,13 @@ JavaScript Array of node Buffers. `HGETALL` returns an Object with Buffers keyed
103
107
104
108
### "ready"
105
109
106
-
`client` will emit `ready` once a connection is established to the Redis server and the server reports
107
-
that it is ready to receive commands. Commands issued before the `ready` event are queued,
110
+
`client` will emit `ready` once a connection is established. Commands issued before the `ready` event are queued,
108
111
then replayed just before this event is emitted.
109
112
110
113
### "connect"
111
114
112
115
`client` will emit `connect` at the same time as it emits `ready` unless `client.options.no_ready_check`
113
-
is set. If this options is set, `connect` will be emitted when the stream is connected, and then
114
-
you are free to try to send commands.
116
+
is set. If this options is set, `connect` will be emitted when the stream is connected.
115
117
116
118
### "reconnecting"
117
119
@@ -120,26 +122,9 @@ are passed an object containing `delay` (in ms) and `attempt` (the attempt #) at
120
122
121
123
### "error"
122
124
123
-
`client` will emit `error` when encountering an error connecting to the Redis server.
124
-
125
-
Note that "error" is a special event type in node. If there are no listeners for an
126
-
"error" event, node will exit. This is usually what you want, but it can lead to some
127
-
cryptic error messages like this:
128
-
129
-
mjr:~/work/node_redis (master)$ node example.js
130
-
131
-
node.js:50
132
-
throw e;
133
-
^
134
-
Error: ECONNREFUSED, Connection refused
135
-
at IOWatcher.callback (net:870:22)
136
-
at node.js:607:9
137
-
138
-
Not very useful in diagnosing the problem, but if your program isn't ready to handle this,
139
-
it is probably the right thing to just exit.
125
+
`client` will emit `error` when encountering an error connecting to the Redis server or when any other in node_redis occurs.
140
126
141
-
`client` will also emit `error` if an exception is thrown inside of `node_redis` for whatever reason.
142
-
It would be nice to distinguish these two cases.
127
+
So please attach the error listener to node_redis.
143
128
144
129
### "end"
145
130
@@ -149,8 +134,7 @@ It would be nice to distinguish these two cases.
149
134
150
135
`client` will emit `drain` when the TCP connection to the Redis server has been buffering, but is now
151
136
writable. This event can be used to stream commands in to Redis and adapt to backpressure. Right now,
152
-
you need to check `client.command_queue.length` to decide when to reduce your send rate. Then you can
153
-
resume sending when you get `drain`.
137
+
you need to check `client.command_queue.length` to decide when to reduce your send rate and resume sending commands when you get `drain`.
154
138
155
139
### "idle"
156
140
@@ -169,39 +153,35 @@ port and host are probably fine and you don't need to supply any arguments. `cre
169
153
170
154
`options` is an object with the following possible properties:
171
155
172
-
*`parser`: which Redis protocol reply parser to use. Defaults to `hiredis` if that module is installed.
173
-
This may also be set to `javascript`.
174
-
*`return_buffers`: defaults to `false`. If set to `true`, then all replies will be sent to callbacks as node Buffer
175
-
objects instead of JavaScript Strings.
176
-
*`detect_buffers`: default to `false`. If set to `true`, then replies will be sent to callbacks as node Buffer objects
177
-
if any of the input arguments to the original command were Buffer objects.
156
+
*`parser`: *hiredis*; Which Redis protocol reply parser to use. If `hiredis` is not installed it will fallback to `javascript`.
157
+
*`return_buffers`: *false*; If set to `true`, then all replies will be sent to callbacks as Buffers instead of Strings.
158
+
*`detect_buffers`: *false*; If set to `true`, then replies will be sent to callbacks as Buffers
159
+
if any of the input arguments to the original command were Buffers.
178
160
This option lets you switch between Buffers and Strings on a per-command basis, whereas `return_buffers` applies to
179
161
every command on a client.
180
-
*`socket_nodelay`: defaults to `true`. Whether to call setNoDelay() on the TCP stream, which disables the
181
-
Nagle algorithm on the underlying socket. Setting this option to `false` can result in additional throughput at the
182
-
cost of more latency. Most applications will want this set to `true`.
183
-
*`socket_keepalive`defaults to `true`. Whether the keep-alive functionality is enabled on the underlying socket.
184
-
*`no_ready_check`: defaults to `false`. When a connection is established to the Redis server, the server might still
185
-
be loading the database from disk. While loading, the server not respond to any commands. To work around this,
162
+
*`socket_nodelay`: *true*; Disables the [Nagle algorithm](https://en.wikipedia.org/wiki/Nagle%27s_algorithm).
163
+
Setting this option to `false` can result in additional throughput at the cost of more latency.
164
+
Most applications will want this set to `true`.
165
+
*`socket_keepalive`*true*; Whether the keep-alive functionality is enabled on the underlying socket.
166
+
*`no_ready_check`: *false*; When a connection is established to the Redis server, the server might still
167
+
be loading the database from disk. While loading the server will not respond to any commands. To work around this,
186
168
`node_redis` has a "ready check" which sends the `INFO` command to the server. The response from the `INFO` command
187
169
indicates whether the server is ready for more commands. When ready, `node_redis` emits a `ready` event.
188
170
Setting `no_ready_check` to `true` will inhibit this check.
189
-
*`enable_offline_queue`: defaults to `true`. By default, if there is no active
171
+
*`enable_offline_queue`: *true*; By default, if there is no active
190
172
connection to the redis server, commands are added to a queue and are executed
191
173
once the connection has been established. Setting `enable_offline_queue` to
192
-
`false` will disable this feature and the callback will be execute immediately
193
-
with an error, or an error will be thrown if no callback is specified.
194
-
*`retry_max_delay`: defaults to `null`. By default every time the client tries to connect and fails time before
195
-
reconnection (delay) almost doubles. This delay normally grows infinitely, but setting `retry_max_delay` limits delay
196
-
to maximum value, provided in milliseconds.
197
-
*`connect_timeout` defaults to `86400000`. Setting `connect_timeout` limits total time for client to reconnect.
198
-
Value is provided in milliseconds and is counted once the disconnect occurred. The last retry is going to happen exactly at the timeout time.
174
+
`false` will disable this feature and the callback will be executed immediately
175
+
with an error, or an error will be emitted if no callback is specified.
176
+
*`retry_max_delay`: *null*; By default every time the client tries to connect and fails the reconnection delay almost doubles.
177
+
This delay normally grows infinitely, but setting `retry_max_delay` limits it to the maximum value, provided in milliseconds.
178
+
*`connect_timeout`*86400000*; Setting `connect_timeout` limits total time for client to reconnect.
179
+
The value is provided in milliseconds and is counted once the disconnect occurred. The last retry is going to happen exactly at the timeout time.
199
180
That way the default is to try reconnecting until 24h passed.
200
-
*`max_attempts`defaults to `0`. By default client will try reconnecting until connected. Setting `max_attempts`
181
+
*`max_attempts`*0*; By default client will try reconnecting until connected. Setting `max_attempts`
201
182
limits total amount of connection tries. Setting this to 1 will prevent any reconnect tries.
202
-
*`auth_pass` defaults to `null`. By default client will try connecting without auth. If set, client will run redis auth command on connect.
203
-
*`family` defaults to `IPv4`. The client connects in IPv4 if not specified or if the DNS resolution returns an IPv4 address.
204
-
You can force an IPv6 if you set the family to 'IPv6'. See nodejs net or dns modules how to use the family type.
183
+
*`auth_pass`*null*; If set, client will run redis auth command on connect.
184
+
*`family`*IPv4*; You can force using IPv6 if you set the family to 'IPv6'. See Node.js [net](https://nodejs.org/api/net.html) or [dns](https://nodejs.org/api/dns.html) modules how to use the family type.
205
185
206
186
```js
207
187
var redis =require("redis"),
@@ -221,11 +201,9 @@ client.get(new Buffer("foo_rand000000000000"), function (err, reply) {
221
201
client.end();
222
202
```
223
203
224
-
225
-
226
204
## client.auth(password, callback)
227
205
228
-
When connecting to Redis servers that require authentication, the `AUTH` command must be sent as the
206
+
When connecting to a Redis server that requires authentication, the `AUTH` command must be sent as the
229
207
first command after connecting. This can be tricky to coordinate with reconnections, the ready check,
230
208
etc. To make this easier, `client.auth()` stashes `password` and will send it after each connection,
231
209
including reconnections. `callback` is invoked only once, after the response to the very first
@@ -247,10 +225,11 @@ var redis = require("redis"),
client.end(); // No further commands will be processed
250
229
client.get("foo_rand000000000000", function (err, reply) {
251
-
console.log(reply.toString());
230
+
// This won't be called anymore
231
+
console.log(err);
252
232
});
253
-
client.end();
254
233
```
255
234
256
235
`client.end()` is useful for timeout cases where something is stuck or taking too long and you want
@@ -436,10 +415,8 @@ client.multi()
436
415
same command methods as `client` objects do. Commands are queued up inside the `Multi` object
437
416
until `Multi.exec()` is invoked.
438
417
439
-
The `callback` of `.exec()` will get invoked with two arguments:
440
-
441
-
*`err`**type:**`null | Array` err is either null or an array of Error Objects corresponding the the sequence the commands where chained. The last item of the array will always be an `EXECABORT` type of error originating from the `.exec()` itself.
442
-
*`results`**type:**`null | Array` results is an array of responses corresponding the the sequence the commands where chained.
418
+
If your code contains an syntax error an EXECABORT error is going to be thrown and all commands are going to be aborted. That error contains a `.errors` property that contains the concret errors.
419
+
If all commands were queued successfully and an error is thrown by redis while processing the commands that error is going to be returned in the result array! No other command is going to be aborted though than the onces failing.
443
420
444
421
You can either chain together `MULTI` commands as in the above example, or you can queue individual
445
422
commands while still sending regular client command as in this example:
@@ -561,7 +538,7 @@ Used internally to send commands to Redis. Nearly all Redis commands have been a
561
538
However, if new commands are introduced before this library is updated, you can use `send_command()` to send arbitrary commands to Redis.
562
539
The command has to be lower case.
563
540
564
-
All commands are sent as multi-bulk commands. `args` can either be an Array of arguments, or omitted.
541
+
All commands are sent as multi-bulk commands. `args` can either be an Array of arguments, or omitted / set to undefined.
565
542
566
543
## client.connected
567
544
@@ -720,22 +697,15 @@ hiredis parser:
720
697
721
698
To get debug output run your `node_redis` application with `NODE_DEBUG=redis`.
722
699
723
-
## TODO
724
-
725
-
1. 100% coverage
726
-
2. More performance improvements
727
-
3. Stream large set/get values into and out of Redis. Otherwise the entire value must be in node's memory.
728
-
4. Performance can be better for very large values in the js parser.
729
-
730
700
## How to Contribute
731
701
- open a pull request and then wait for feedback
732
702
733
703
## Contributors
734
-
Many people have have added features and fixed bugs in `node_redis`. Thanks to all of them!
704
+
Many [people](https://github.com/NodeRedis/node_redis/graphs/contributors) have have added features and fixed bugs in `node_redis`. Thanks to all of them!
735
705
736
706
## LICENSE - "MIT License"
737
707
738
-
Copyright (c) 2015 Matthew Ranney, http://ranney.com/
708
+
Copyright (c) by NodeRedis
739
709
740
710
Permission is hereby granted, free of charge, to any person
741
711
obtaining a copy of this software and associated documentation
@@ -757,3 +727,5 @@ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
757
727
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
758
728
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
759
729
OTHER DEALINGS IN THE SOFTWARE.
730
+
731
+
Originally developed by Matthew Ranney, http://ranney.com/
0 commit comments