redis failover solution based on ZooKeeper

npm install node-redis-failover
35 downloads in the last month

Node Redis Failover NPM version

A redis failover solution based on ZooKeeper for Node.js

Architecture chart:



  • Automatic master/slave failover
  • Read/Write Splitting
  • All components high availability


Install with npm:

npm install -g node-redis-failover


Start redis watcher

redis-failover -h

  Usage: redis-failover -n, -z,,


    -h, --help                  output usage information
    -V, --version               output the version number
    -n, --nodes <nodes>         Comma-separated redis host:port pairs
    -z, --zk-servers <servers>  Comma-separated ZooKeeper host:port pairs
    -p, --password [password]   Redis password
    -c, --config [path]         Path to JSON config file
    -l, --log [path]            The log file path
    --zk-chroot [rootpath]      Path to ZooKeepers chroot
    --zk-username [username]    ZooKeepers username
    --zk-password [password]    ZooKeepers password

start a redis watcher (we recommend the wathers' count should be an odd number, and more than 3):

redis-failover -n, -z,,

with a config file config.json (config json file support comments use json-comments):

  // redis nodes
  "nodes": ",,",
  // redis password
  //"password": "abc123",

  // redis ping timeout default 6000ms
  //"pingTimeout": 6000,

  // redis ping interval(ms). default 3000ms
  //"pingInterval": 3000,

  // the maxFailures for the redis. default 3
  //"maxFailures": 3,

  // zookeeper nodes
  "zkServers": "",
  // zookeeper chroot
  "zkChroot": "/test",

  // log path
  "log": "logs/",

  // pid file
  "pid": ""

start a watcher:

redis-failover -c config.json

start with forever

forever start -m 10 redis-failover -c config.json

Use redis in your application


npm install node-redis-failover --save

example code:

var redisFailover = require('node-redis-failover');

var zookeeper = {
  servers: ',,',
  chroot: '/appName'

var redis = redisFailover.createClient(zookeeper);

redis.on('ready', function() {
  // master client, res){
    console.log('ping master', res);

  // slave client
  redis.getClient('slave').ping(function(err, res) {
    console.log('ping slave', res);

// catch error
redis.on('error', function(err) {

redis.on('change', function() {
  console.log('redis state changed, %j', redis.redisState);

redis.on('masterChange', function() {
  console.log('master changed, %s', redis.masterClient);


(The MIT License)

Copyright (c) 2013 Johnny Wong

Bitdeli Badge

npm loves you