@@ -4,9 +4,8 @@ redis - a node.js redis client
4
4
[ ![ Build Status] ( https://travis-ci.org/NodeRedis/node_redis.png )] ( https://travis-ci.org/NodeRedis/node_redis )
5
5
[ ![ Coverage Status] ( https://coveralls.io/repos/NodeRedis/node_redis/badge.svg?branch= )] ( https://coveralls.io/r/NodeRedis/node_redis?branch= )
6
6
7
- This is a complete Redis client for node.js. It supports all Redis commands,
8
- including many recently added commands like EVAL from experimental Redis server
9
- branches.
7
+ This is a complete Redis client for node.js. It supports all Redis commands,
8
+ including many recently added commands.
10
9
11
10
Install with:
12
11
@@ -89,11 +88,11 @@ client.get("missingkey", function(err, reply) {
89
88
90
89
For a list of Redis commands, see [ Redis Command Reference] ( http://redis.io/commands )
91
90
92
- The commands can be specified in uppercase or lowercase for convenience. ` client.get() ` is the same as ` client.GET() ` .
91
+ The commands can be specified in uppercase or lowercase for convenience. ` client.get() ` is the same as ` client.GET() ` .
93
92
94
- Minimal parsing is done on the replies. Commands that return a single line reply return JavaScript Strings,
93
+ Minimal parsing is done on the replies. Commands that return a single line reply return JavaScript Strings,
95
94
integer replies return JavaScript Numbers, "bulk" replies return node Buffers, and "multi bulk" replies return a
96
- JavaScript Array of node Buffers. ` HGETALL ` returns an Object with Buffers keyed by the hash keys.
95
+ JavaScript Array of node Buffers. ` HGETALL ` returns an Object with Buffers keyed by the hash keys.
97
96
98
97
# API
99
98
@@ -104,21 +103,21 @@ JavaScript Array of node Buffers. `HGETALL` returns an Object with Buffers keye
104
103
### "ready"
105
104
106
105
` 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,
106
+ that it is ready to receive commands. Commands issued before the ` ready ` event are queued,
108
107
then replayed just before this event is emitted.
109
108
110
109
### "connect"
111
110
112
111
` 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
112
+ is set. If this options is set, ` connect ` will be emitted when the stream is connected, and then
114
113
you are free to try to send commands.
115
114
116
115
### "error"
117
116
118
117
` client ` will emit ` error ` when encountering an error connecting to the Redis server.
119
118
120
- Note that "error" is a special event type in node. If there are no listeners for an
121
- "error" event, node will exit. This is usually what you want, but it can lead to some
119
+ Note that "error" is a special event type in node. If there are no listeners for an
120
+ "error" event, node will exit. This is usually what you want, but it can lead to some
122
121
cryptic error messages like this:
123
122
124
123
mjr:~/work/node_redis (master)$ node example.js
@@ -143,8 +142,8 @@ It would be nice to distinguish these two cases.
143
142
### "drain"
144
143
145
144
` client ` will emit ` drain ` when the TCP connection to the Redis server has been buffering, but is now
146
- writable. This event can be used to stream commands in to Redis and adapt to backpressure. Right now,
147
- you need to check ` client.command_queue.length ` to decide when to reduce your send rate. Then you can
145
+ writable. This event can be used to stream commands in to Redis and adapt to backpressure. Right now,
146
+ you need to check ` client.command_queue.length ` to decide when to reduce your send rate. Then you can
148
147
resume sending when you get ` drain ` .
149
148
150
149
### "idle"
@@ -163,22 +162,22 @@ port and host are probably fine and you don't need to supply any arguments. `cre
163
162
164
163
` options ` is an object with the following possible properties:
165
164
166
- * ` parser ` : which Redis protocol reply parser to use. Defaults to ` hiredis ` if that module is installed.
165
+ * ` parser ` : which Redis protocol reply parser to use. Defaults to ` hiredis ` if that module is installed.
167
166
This may also be set to ` javascript ` .
168
- * ` return_buffers ` : defaults to ` false ` . If set to ` true ` , then all replies will be sent to callbacks as node Buffer
167
+ * ` return_buffers ` : defaults to ` false ` . If set to ` true ` , then all replies will be sent to callbacks as node Buffer
169
168
objects instead of JavaScript Strings.
170
169
* ` detect_buffers ` : default to ` false ` . If set to ` true ` , then replies will be sent to callbacks as node Buffer objects
171
170
if any of the input arguments to the original command were Buffer objects.
172
171
This option lets you switch between Buffers and Strings on a per-command basis, whereas ` return_buffers ` applies to
173
172
every command on a client.
174
173
* ` socket_nodelay ` : defaults to ` true ` . Whether to call setNoDelay() on the TCP stream, which disables the
175
- Nagle algorithm on the underlying socket. Setting this option to ` false ` can result in additional throughput at the
176
- cost of more latency. Most applications will want this set to ` true ` .
174
+ Nagle algorithm on the underlying socket. Setting this option to ` false ` can result in additional throughput at the
175
+ cost of more latency. Most applications will want this set to ` true ` .
177
176
* ` socket_keepalive ` defaults to ` true ` . Whether the keep-alive functionality is enabled on the underlying socket.
178
177
* ` no_ready_check ` : defaults to ` false ` . When a connection is established to the Redis server, the server might still
179
- be loading the database from disk. While loading, the server not respond to any commands. To work around this,
180
- ` node_redis ` has a "ready check" which sends the ` INFO ` command to the server. The response from the ` INFO ` command
181
- indicates whether the server is ready for more commands. When ready, ` node_redis ` emits a ` ready ` event.
178
+ be loading the database from disk. While loading, the server not respond to any commands. To work around this,
179
+ ` node_redis ` has a "ready check" which sends the ` INFO ` command to the server. The response from the ` INFO ` command
180
+ indicates whether the server is ready for more commands. When ready, ` node_redis ` emits a ` ready ` event.
182
181
Setting ` no_ready_check ` to ` true ` will inhibit this check.
183
182
* ` enable_offline_queue ` : defaults to ` true ` . By default, if there is no active
184
183
connection to the redis server, commands are added to a queue and are executed
@@ -219,20 +218,20 @@ client.end();
219
218
## client.auth(password, callback)
220
219
221
220
When connecting to Redis servers that require authentication, the ` AUTH ` command must be sent as the
222
- first command after connecting. This can be tricky to coordinate with reconnections, the ready check,
223
- etc. To make this easier, ` client.auth() ` stashes ` password ` and will send it after each connection,
224
- including reconnections. ` callback ` is invoked only once, after the response to the very first
221
+ first command after connecting. This can be tricky to coordinate with reconnections, the ready check,
222
+ etc. To make this easier, ` client.auth() ` stashes ` password ` and will send it after each connection,
223
+ including reconnections. ` callback ` is invoked only once, after the response to the very first
225
224
` AUTH ` command sent.
226
225
NOTE: Your call to ` client.auth() ` should not be inside the ready handler. If
227
226
you are doing this wrong, ` client ` will emit an error that looks
228
227
something like this ` Error: Ready check failed: ERR operation not permitted ` .
229
228
230
229
## client.end()
231
230
232
- Forcibly close the connection to the Redis server. Note that this does not wait until all replies have been parsed.
231
+ Forcibly close the connection to the Redis server. Note that this does not wait until all replies have been parsed.
233
232
If you want to exit cleanly, call ` client.quit() ` to send the ` QUIT ` command after you have handled all replies.
234
233
235
- This example closes the connection to the Redis server before the replies have been read. You probably don't
234
+ This example closes the connection to the Redis server before the replies have been read. You probably don't
236
235
want to do this:
237
236
238
237
``` js
@@ -276,7 +275,7 @@ When dealing with hash values, there are a couple of useful exceptions to this.
276
275
277
276
### client.hgetall(hash)
278
277
279
- The reply from an HGETALL command will be converted into a JavaScript Object by ` node_redis ` . That way you can interact
278
+ The reply from an HGETALL command will be converted into a JavaScript Object by ` node_redis ` . That way you can interact
280
279
with the responses using JavaScript syntax.
281
280
282
281
Example:
@@ -317,7 +316,7 @@ client.HMSET(key1, "0123456789", "abcdefghij", "some manner of key", "a type of
317
316
318
317
## Publish / Subscribe
319
318
320
- Here is a simple example of the API for publish / subscribe. This program opens two
319
+ Here is a simple example of the API for publish / subscribe. This program opens two
321
320
client connections, subscribes to a channel on one of them, and publishes to that
322
321
channel on the other:
323
322
@@ -347,7 +346,7 @@ client1.subscribe("a nice channel");
347
346
```
348
347
349
348
When a client issues a ` SUBSCRIBE ` or ` PSUBSCRIBE ` , that connection is put into a "subscriber" mode.
350
- At that point, only commands that modify the subscription set are valid. When the subscription
349
+ At that point, only commands that modify the subscription set are valid. When the subscription
351
350
set is empty, the connection is put back into regular mode.
352
351
353
352
If you need to send regular commands to Redis while in subscriber mode, just open another connection.
@@ -369,30 +368,30 @@ name as `channel`, and the message Buffer as `message`.
369
368
370
369
### "subscribe" (channel, count)
371
370
372
- Client will emit ` subscribe ` in response to a ` SUBSCRIBE ` command. Listeners are passed the
371
+ Client will emit ` subscribe ` in response to a ` SUBSCRIBE ` command. Listeners are passed the
373
372
channel name as ` channel ` and the new count of subscriptions for this client as ` count ` .
374
373
375
374
### "psubscribe" (pattern, count)
376
375
377
- Client will emit ` psubscribe ` in response to a ` PSUBSCRIBE ` command. Listeners are passed the
376
+ Client will emit ` psubscribe ` in response to a ` PSUBSCRIBE ` command. Listeners are passed the
378
377
original pattern as ` pattern ` , and the new count of subscriptions for this client as ` count ` .
379
378
380
379
### "unsubscribe" (channel, count)
381
380
382
- Client will emit ` unsubscribe ` in response to a ` UNSUBSCRIBE ` command. Listeners are passed the
383
- channel name as ` channel ` and the new count of subscriptions for this client as ` count ` . When
381
+ Client will emit ` unsubscribe ` in response to a ` UNSUBSCRIBE ` command. Listeners are passed the
382
+ channel name as ` channel ` and the new count of subscriptions for this client as ` count ` . When
384
383
` count ` is 0, this client has left subscriber mode and no more subscriber events will be emitted.
385
384
386
385
### "punsubscribe" (pattern, count)
387
386
388
- Client will emit ` punsubscribe ` in response to a ` PUNSUBSCRIBE ` command. Listeners are passed the
389
- channel name as ` channel ` and the new count of subscriptions for this client as ` count ` . When
387
+ Client will emit ` punsubscribe ` in response to a ` PUNSUBSCRIBE ` command. Listeners are passed the
388
+ channel name as ` channel ` and the new count of subscriptions for this client as ` count ` . When
390
389
` count ` is 0, this client has left subscriber mode and no more subscriber events will be emitted.
391
390
392
391
## client.multi([ commands] )
393
392
394
393
` MULTI ` commands are queued up until an ` EXEC ` is issued, and then all commands are run atomically by
395
- Redis. The interface in ` node_redis ` is to return an individual ` Multi ` object by calling ` client.multi() ` .
394
+ Redis. The interface in ` node_redis ` is to return an individual ` Multi ` object by calling ` client.multi() ` .
396
395
397
396
``` js
398
397
var redis = require (" ./index" ),
@@ -426,8 +425,8 @@ client.multi()
426
425
427
426
### Multi.exec( callback )
428
427
429
- ` client.multi() ` is a constructor that returns a ` Multi ` object. ` Multi ` objects share all of the
430
- same command methods as ` client ` objects do. Commands are queued up inside the ` Multi ` object
428
+ ` client.multi() ` is a constructor that returns a ` Multi ` object. ` Multi ` objects share all of the
429
+ same command methods as ` client ` objects do. Commands are queued up inside the ` Multi ` object
431
430
until ` Multi.exec() ` is invoked.
432
431
433
432
The ` callback ` of ` .exec() ` will get invoked with two arguments:
@@ -484,8 +483,8 @@ client.multi([
484
483
Redis supports the ` MONITOR ` command, which lets you see all commands received by the Redis server
485
484
across all client connections, including from other client libraries and other computers.
486
485
487
- After you send the ` MONITOR ` command, no other commands are valid on that connection. ` node_redis `
488
- will emit a ` monitor ` event for every new monitor message that comes across. The callback for the
486
+ After you send the ` MONITOR ` command, no other commands are valid on that connection. ` node_redis `
487
+ will emit a ` monitor ` event for every new monitor message that comes across. The callback for the
489
488
` monitor ` event takes a timestamp from the Redis server and an array of command arguments.
490
489
491
490
Here is a simple example:
@@ -521,7 +520,7 @@ The `versions` key contains an array of the elements of the version string for e
521
520
522
521
## redis.print()
523
522
524
- A handy callback function for displaying return values when testing. Example:
523
+ A handy callback function for displaying return values when testing. Example:
525
524
526
525
``` js
527
526
var redis = require (" redis" ),
@@ -581,36 +580,36 @@ the second word as first parameter:
581
580
582
581
## client.send_command(command_name, args, callback)
583
582
584
- Used internally to send commands to Redis. For convenience, nearly all commands that are published on the Redis
585
- Wiki have been added to the ` client ` object. However, if I missed any, or if new commands are introduced before
583
+ Used internally to send commands to Redis. For convenience, nearly all commands that are published on the Redis
584
+ Wiki have been added to the ` client ` object. However, if I missed any, or if new commands are introduced before
586
585
this library is updated, you can use ` send_command() ` to send arbitrary commands to Redis.
587
586
588
- All commands are sent as multi-bulk commands. ` args ` can either be an Array of arguments, or omitted.
587
+ All commands are sent as multi-bulk commands. ` args ` can either be an Array of arguments, or omitted.
589
588
590
589
## client.connected
591
590
592
591
Boolean tracking the state of the connection to the Redis server.
593
592
594
593
## client.command_queue.length
595
594
596
- The number of commands that have been sent to the Redis server but not yet replied to. You can use this to
595
+ The number of commands that have been sent to the Redis server but not yet replied to. You can use this to
597
596
enforce some kind of maximum queue depth for commands while connected.
598
597
599
598
Don't mess with ` client.command_queue ` though unless you really know what you are doing.
600
599
601
600
## client.offline_queue.length
602
601
603
- The number of commands that have been queued up for a future connection. You can use this to enforce
602
+ The number of commands that have been queued up for a future connection. You can use this to enforce
604
603
some kind of maximum queue depth for pre-connection commands.
605
604
606
605
## client.retry_delay
607
606
608
- Current delay in milliseconds before a connection retry will be attempted. This starts at ` 250 ` .
607
+ Current delay in milliseconds before a connection retry will be attempted. This starts at ` 250 ` .
609
608
610
609
## client.retry_backoff
611
610
612
- Multiplier for future retry timeouts. This should be larger than 1 to add more time between retries.
613
- Defaults to 1.7. The default initial connection retry is 250, so the second retry will be 425, followed by 723.5, etc.
611
+ Multiplier for future retry timeouts. This should be larger than 1 to add more time between retries.
612
+ Defaults to 1.7. The default initial connection retry is 250, so the second retry will be 425, followed by 723.5, etc.
614
613
615
614
### Commands with Optional and Keyword arguments
616
615
@@ -648,7 +647,7 @@ operations. As pipelining happens naturally from shared connections, overall
648
647
efficiency goes up.
649
648
650
649
Here are typical results of ` multi_bench.js ` which is similar to
651
- ` redis-benchmark ` from the Redis distribution. It uses 5 concurrent connections
650
+ ` redis-benchmark ` from the Redis distribution. It uses 5 concurrent connections
652
651
and shows the difference between pipelines of 1 and 50.
653
652
654
653
JavaScript parser:
@@ -697,7 +696,7 @@ If the `hiredis` npm module is installed, `node_redis` will use it by default.
697
696
Otherwise, the pure JavaScript parser will be used.
698
697
699
698
If you use ` hiredis ` , be sure to rebuild it whenever you upgrade your version of
700
- node. There are mysterious failures that can happen between node and native
699
+ node. There are mysterious failures that can happen between node and native
701
700
code modules after a node upgrade.
702
701
703
702
Most users find that the JS parser is faster than the ` hiredis ` parser. Because
@@ -742,65 +741,20 @@ hiredis parser:
742
741
743
742
## TODO
744
743
745
- Better tests for auth, disconnect/reconnect, and all combinations thereof.
746
-
747
- Stream large set/get values into and out of Redis. Otherwise the entire value must be in node's memory.
748
-
749
- Performance can be better for very large values.
750
-
751
- I think there are more performance improvements left in there for smaller values, especially for large lists of small values.
744
+ 1 . 100% coverage
745
+ 2 . More performance improvements
746
+ 3 . Stream large set/get values into and out of Redis. Otherwise the entire value must be in node's memory.
747
+ 4 . Performance can be better for very large values in the js parser.
752
748
753
749
## How to Contribute
754
- - open a pull request and then wait for feedback (if
755
- [ DTrejo] ( http://github.com/dtrejo ) does not get back to you within 2 days,
756
- comment again with indignation!)
750
+ - open a pull request and then wait for feedback
757
751
758
752
## Contributors
759
- Many people have have added features and fixed bugs in ` node_redis ` .
760
-
761
- Ordered by date of first contribution.
762
- [ Auto-generated] ( http://github.com/dtrejo/node-authors ) on Wed Jul 25 2012 19:14:59 GMT-0700 (PDT).
763
-
764
- - [ Matt Ranney aka ` mranney ` ] ( https://github.com/mranney )
765
- - [ Tim-Smart aka ` tim-smart ` ] ( https://github.com/tim-smart )
766
- - [ Tj Holowaychuk aka ` visionmedia ` ] ( https://github.com/visionmedia )
767
- - [ rick aka ` technoweenie ` ] ( https://github.com/technoweenie )
768
- - [ Orion Henry aka ` orionz ` ] ( https://github.com/orionz )
769
- - [ Aivo Paas aka ` aivopaas ` ] ( https://github.com/aivopaas )
770
- - [ Hank Sims aka ` hanksims ` ] ( https://github.com/hanksims )
771
- - [ Paul Carey aka ` paulcarey ` ] ( https://github.com/paulcarey )
772
- - [ Pieter Noordhuis aka ` pietern ` ] ( https://github.com/pietern )
773
- - [ nithesh aka ` nithesh ` ] ( https://github.com/nithesh )
774
- - [ Andy Ray aka ` andy2ray ` ] ( https://github.com/andy2ray )
775
- - [ unknown aka ` unknowdna ` ] ( https://github.com/unknowdna )
776
- - [ Dave Hoover aka ` redsquirrel ` ] ( https://github.com/redsquirrel )
777
- - [ Vladimir Dronnikov aka ` dvv ` ] ( https://github.com/dvv )
778
- - [ Umair Siddique aka ` umairsiddique ` ] ( https://github.com/umairsiddique )
779
- - [ Louis-Philippe Perron aka ` lp ` ] ( https://github.com/lp )
780
- - [ Mark Dawson aka ` markdaws ` ] ( https://github.com/markdaws )
781
- - [ Ian Babrou aka ` bobrik ` ] ( https://github.com/bobrik )
782
- - [ Felix Geisendörfer aka ` felixge ` ] ( https://github.com/felixge )
783
- - [ Jean-Hugues Pinson aka ` undefined ` ] ( https://github.com/undefined )
784
- - [ Maksim Lin aka ` maks ` ] ( https://github.com/maks )
785
- - [ Owen Smith aka ` orls ` ] ( https://github.com/orls )
786
- - [ Zachary Scott aka ` zzak ` ] ( https://github.com/zzak )
787
- - [ TEHEK Firefox aka ` TEHEK ` ] ( https://github.com/TEHEK )
788
- - [ Isaac Z. Schlueter aka ` isaacs ` ] ( https://github.com/isaacs )
789
- - [ David Trejo aka ` DTrejo ` ] ( https://github.com/DTrejo )
790
- - [ Brian Noguchi aka ` bnoguchi ` ] ( https://github.com/bnoguchi )
791
- - [ Philip Tellis aka ` bluesmoon ` ] ( https://github.com/bluesmoon )
792
- - [ Marcus Westin aka ` marcuswestin2 ` ] ( https://github.com/marcuswestin2 )
793
- - [ Jed Schmidt aka ` jed ` ] ( https://github.com/jed )
794
- - [ Dave Peticolas aka ` jdavisp3 ` ] ( https://github.com/jdavisp3 )
795
- - [ Trae Robrock aka ` trobrock ` ] ( https://github.com/trobrock )
796
- - [ Shankar Karuppiah aka ` shankar0306 ` ] ( https://github.com/shankar0306 )
797
- - [ Ignacio Burgueño aka ` ignacio ` ] ( https://github.com/ignacio )
798
-
799
- Thanks.
753
+ Many people have have added features and fixed bugs in ` node_redis ` . Thanks to all of them!
800
754
801
755
## LICENSE - "MIT License"
802
756
803
- Copyright (c) 2010 Matthew Ranney, http://ranney.com/
757
+ Copyright (c) 2015 Matthew Ranney, http://ranney.com/
804
758
805
759
Permission is hereby granted, free of charge, to any person
806
760
obtaining a copy of this software and associated documentation
0 commit comments