# node-redis-failover

> redis failover solution based on ZooKeeper

Latest version **0.2.5** (published 2014-06-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-redis-failover
pnpm add node-redis-failover
yarn add node-redis-failover
bun add node-redis-failover
```

Provides the command `redis-failover`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.5 |
| Published | 2014-06-09 |
| First published | 2013-10-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.8 |
| Dependencies | 6 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 21 |
| Author | numbcoder |
| Maintainers | numbcoder |
| Keywords | redis, failover, high availability, zookeeper, cluster |

## Links

- npm: https://www.npmjs.com/package/node-redis-failover
- Repository: https://github.com/numbcoder/node-redis-failover
- Issues: https://github.com/numbcoder/node-redis-failover/issues
- npm.io page: https://npm.io/package/node-redis-failover

## Dependencies (6)

- [async](https://npm.io/package/async.md) 0.2.9
- [redis](https://npm.io/package/redis.md) 0.10.3
- [log4js](https://npm.io/package/log4js.md) 0.6.14
- [commander](https://npm.io/package/commander.md) 2.2.0
- [json-comments](https://npm.io/package/json-comments.md) 0.2.1
- [node-zookeeper-client](https://npm.io/package/node-zookeeper-client.md) 0.2.1

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 0.2.5 (latest) — 2014-06-09
- 0.2.4 — 2014-05-28
- 0.2.3 — 2014-05-22
- 0.2.2 — 2014-02-17
- 0.2.1 — 2014-01-23
- 0.2.0 — 2014-01-21
- 0.1.9 — 2014-01-15
- 0.1.8 — 2013-12-27
- 0.1.7 — 2013-12-04
- 0.1.6 — 2013-11-25
- 0.1.5 — 2013-10-23
- 0.1.4 — 2013-10-18
- 0.1.3 — 2013-10-18
- 0.1.2 — 2013-10-17
- 0.1.1 — 2013-10-16
- … 1 more at https://npm.io/package/node-redis-failover/versions

## README

Node Redis Failover ![NPM version](https://badge.fury.io/js/node-redis-failover.png)
=======
A redis failover solution based on ZooKeeper for Node.js

Architecture chart:

![Architecture](http://ww1.sinaimg.cn/large/60512853gw1e9qzaunhsij20dw0bi752.jpg)

## Features

* Automatic master/slave failover
* Read/Write Splitting
* All components high availability
* Support cluster
* Custom sharding router

## Installation
Install with npm:

```shell
npm install -g node-redis-failover
```

## Usage

### Start redis watcher

```shell
redis-failover -h

  Usage: redis-failover -c config.json

  Options:

    -h, --help           output usage information
    -V, --version        output the version number
    -c, --config [path]  Path to JSON config file
```

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

```shell
redis-failover -c config.json
```

with a config file `config.json` (config json file support comments use [json-comments](https://github.com/numbcoder/json-comments)):

```js
{
  // zookeeper
  "zooKeeper": {
    "servers": "127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183",
    "chroot": "/test"
    //"username": "abssd",
    //"password": 'asdfefe'
  },
  // redis cluster nodes
  "nodes": [
    {
      "name": "node_1",
      "servers": "127.0.0.1:6379,127.0.0.1:6479",
      // redis password
      "password": "abc123",
      // redis ping timeout default 6000 ms
      "pingTimeout": 4000,

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

      // the maxFailures for the redis. default 3
      "maxFailures": 5
    },
    {
      "name": "node_2",
      "servers": "127.0.0.1:7000,127.0.0.1:7001"
    }
  ],

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

  // pid file
  "pid": "a.pid"
}
```

start a watcher:

```bash
redis-failover -c config.json
```

start with `forever`

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


### Use redis in your application

install:

```shell
npm install node-redis-failover --save
```

example code:

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

var zookeeper = {
  servers: '192.168.1.1:2181,192.168.1.2:2181,192.168.1.3:2181',
  chroot: '/appName'
};

var redis = redisFailover.createClient(zookeeper);

redis.on('ready', function() {
  // get the master client of 'node_1' (default master)
  redis.getClient('node_1').ping(function(err, info) {
    console.log(info);
  });

  // get the slave clinet of 'node_2'
  redis.getClient('node_1', 'slave').ping(function(err, info) {
    console.log(info);
  });
});

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

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

redis.on('error', function(err) {
  console.log('err,', err);
});

```

## License

(The MIT License)

Copyright (c) 2014 Johnny Wong <wzhao23@gmail.com>


[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/numbcoder/node-redis-failover/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

---
_Source: https://npm.io/package/node-redis-failover · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
