Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
Removing the negative example
  • Loading branch information
BrianRossmajer committed Jun 5, 2016
1 parent 6c118c3 commit fc2c0dd
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -618,38 +618,33 @@ 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.

An example of when to use duplicate() would be to accomodate the connection-
One example of when to use duplicate() would be to accomodate the connection-
blocking redis commands BRPOP, BLPOP, and BRPOPLPUSH. If these commands
are used on the same redisClient instance as non-blocking commands, the
non-blocking ones may be queued up until after the blocking ones finish.

var Redis=require('redis');
var client = Redis.createClient();
var clientBlocking = client.duplicate();

var get = function() {
console.log("get called");
client.get("any_key",function() { console.log("get returned"); });
setTimeout( get, 1000 );
};
var brpop = function() {
console.log("brpop called");
client.brpop("nonexistent", 5, function() {
clientBlocking.brpop("nonexistent", 5, function() {
console.log("brpop return");
setTimeout( brpop, 1000 );
});
};
get();
brpop();

These two repeating functions will interfere with each other -- the `get`s will
not return until after the `brpop` returns. This can be fixed by keeping the
blocking calls separate using `client.duplicate()`, eg:

...
var clientBlocking = client.duplicate();
var brpop = function() {
console.log("brpop called");
clientBlocking.brpop( ...

Another reason to use duplicate() is when multiple DBs on the same server are
accessed via the redis SELECT command. Each DB could use its own connection.

## client.send_command(command_name[, [args][, callback]])

All Redis commands have been added to the `client` object. However, if new commands are introduced before this library is updated,
Expand Down

0 comments on commit fc2c0dd

Please sign in to comment.