Sentinel client for redis
Switch branches/tags
Clone or download
Latest commit 8171766 Jun 30, 2015
Type Name Latest commit message Commit time
Failed to load latest commit information.
test Add missing expectation re: clients.length, don't do unnecessary check Mar 5, 2015
.gitignore initial redis-sentinel commit Mar 11, 2013 Update Jun 30, 2015
index.js Fix #43 Jun 16, 2015
package.json bump version Jun 16, 2015


I recommend using ioredis rather than this library. It has inbuilt sentinel support and is likely much more robust

Wrapper around node_redis creating a client pointing at the master server which autoupdates when the master goes down.

var sentinel = require('redis-sentinel');

// List the sentinel endpoints
var endpoints = [
    {host: '', port: 26379},
    {host: '', port: 26380}

var opts = {}; // Standard node_redis client options
var masterName = 'mymaster';

// masterName and opts are optional - masterName defaults to 'mymaster'
var redisClient = sentinel.createClient(endpoints, masterName, opts);

// redisClient is a normal redis client, except that if the master goes down
// it will keep checking the sentinels for a new master and then connect to that.
// No need to monitor for reconnects etc - everything handled transparently
// Anything that persists over the normal node_redis reconnect will persist here. 
// Anything that doesn't, won't.

// An equivalent way of doing the above (if you don't want to have to pass the endpoints around all the time) is
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.

// The master is the default case if no role is specified.
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.


  • We could probably be cleverer with reconnects etc. and there may be issues with the error handling