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
Copy file name to clipboardExpand all lines: README.md
+44-32Lines changed: 44 additions & 32 deletions
Original file line number
Diff line number
Diff line change
@@ -19,44 +19,56 @@ If you use `hiredis`, be sure to rebuild it whenever you upgrade your version of
19
19
happen between node and native code modules after a node upgrade.
20
20
21
21
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 =newRedisMetaClient("mymaster", sentinels);
34
+
var i =0;
35
+
36
+
var client =redisMetaClient.createMasterClient();
37
+
client.on('error', function(error){
38
+
console.log(error);
39
+
});
23
40
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
+
```
25
53
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();`
29
55
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).
32
60
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.
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
59
68
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
0 commit comments