Skip to content

Commit a71a034

Browse files
Updated README
1 parent dd6b8db commit a71a034

File tree

1 file changed

+44
-32
lines changed

1 file changed

+44
-32
lines changed

README.md

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,44 +19,56 @@ If you use `hiredis`, be sure to rebuild it whenever you upgrade your version of
1919
happen between node and native code modules after a node upgrade.
2020

2121

22-
## Usage
22+
## Sentinel Usage
23+
24+
Simple example of a sentinel-aware client
25+
26+
```javascript
27+
var RedisMetaClient = require("./../node_redis/sentinel").RedisMetaClient;
28+
var sentinels = [
29+
{host: "127.0.0.1", port: 26382},
30+
{host: "127.0.0.1", port: 26383},
31+
{host: "127.0.0.1", port: 26384}
32+
];
33+
var redisMetaClient = new RedisMetaClient("mymaster", sentinels);
34+
var i = 0;
35+
36+
var client = redisMetaClient.createMasterClient();
37+
client.on('error', function(error){
38+
console.log(error);
39+
});
2340

24-
Simple example, included as `examples/simple.js`:
41+
setInterval(function(){
42+
client.set('test:' + i, i, function(error, result){
43+
if(!error){
44+
console.log('success, ' + i);
45+
++i;
46+
}
47+
else {
48+
console.log('error, ' + i);
49+
}
50+
});
51+
}, 500);
52+
```
2553

26-
```js
27-
var redis = require("redis"),
28-
client = redis.createClient();
54+
Basically, you first have to create a 'RedisMetaClient', configured with the name of the master and a list of sentinels. Then, calling `redisMetaClient.createMasterClient();` will give you a client similar to the usual `redis.createClient();`
2955

30-
// if you'd like to select database 3, instead of 0 (default), call
31-
// client.select(3, function() { /* ... */ });
56+
## What works:
57+
- Basic functionnality, ie. setup of the correct master, failover... If the master change, all the current masterClients (created by `redisMetaClient.createMasterClient();` will be updated to point to the new master, so that one doesn't need to look for client.on('error') to update the connection.
58+
I have try to preserve the idea of an offline queue, ie. being able to send commands before the master is found and configured.
59+
- I have tested with simple requests, pub/sub... but not with multi (may work, just not sure).
3260

33-
client.on("error", function (err) {
34-
console.log("Error " + err);
35-
});
61+
## How was is it done:
62+
I've tried to modify as less as possible the code and behaviour of the single client (what's in 'client.js'). sentinel.js contains kind of a wrapper around client.js, to deal with sentinels.
3663

37-
client.set("string key", "string val", redis.print);
38-
client.hset("hash key", "hashtest 1", "some value", redis.print);
39-
client.hset(["hash key", "hashtest 2", "some other value"], redis.print);
40-
client.hkeys("hash key", function (err, replies) {
41-
console.log(replies.length + " replies:");
42-
replies.forEach(function (reply, i) {
43-
console.log(" " + i + ": " + reply);
44-
});
45-
client.quit();
46-
});
47-
```
48-
49-
This will display:
50-
51-
mjr:~/work/node_redis (master)$ node example.js
52-
Reply: OK
53-
Reply: 0
54-
Reply: 0
55-
2 replies:
56-
0: hashtest 1
57-
1: hashtest 2
58-
mjr:~/work/node_redis (master)$
64+
## What remains to be done:
65+
- Dealing with slaves (for now, nothing is done around them).
66+
- Testing (both by hand and automatic) of multiple scenarios
67+
- Documentation
5968

69+
## Known issues:
70+
- the event `ready` is triggered multiple times for a masterClient if a failover happened, which can result in unexpected behaviours based on the way it's used
71+
- many others that I don't know about
6072

6173
## Performance
6274

0 commit comments

Comments
 (0)