node-redis-sentinel
Wrapper around node_redis creating a client pointing at the master server which autoupdates when the master goes down.
var sentinel = require('redis-sentinel');
var endpoints = [
{host: '127.0.0.1', port: 26379},
{host: '127.0.0.1', port: 26380}
];
var opts = {};
var masterName = 'mymaster';
var redisClient = sentinel.createClient(endpoints, masterName, opts);
var Sentinel = sentinel.Sentinel(endpoints);
var masterClient = Sentinel.createClient(masterName, opts);
Connection to slaves or the sentinel itself
You can get a connection to a slave (chosen at random) or the first available sentinel from the endpoints by passing in the role
attribute in the options. E.g.
var masterClient = sentinel.createClient(endpoints, masterName, {role: 'master'});
var slaveClient = sentinel.createClient(endpoints, masterName, {role: 'slave'});
var sentinelClient = sentinel.createClient(endpoints, {role: 'sentinel'});
Where you should also transparently get a reconnection to a new slave/sentinel if the existing one goes down.
TODO
- We could probably be cleverer with reconnects etc. and there may be issues with the error handling
Licence
MIT