# redis-client-ch

> use zookeeper mangage redis cluster and write to master and read from slave

Latest version **0.1.6** (published 2014-12-18) · ISC license · 0 weekly downloads

## Install

```sh
npm install redis-client-ch
pnpm add redis-client-ch
yarn add redis-client-ch
bun add redis-client-ch
```

## 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.1.6 |
| Published | 2014-12-18 |
| First published | 2014-07-31 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | morningzhang |
| Maintainers | blogmorning |
| Keywords | redis, zookeeper, HA |

## Links

- npm: https://www.npmjs.com/package/redis-client-ch
- Repository: https://github.com/morningzhang/redis-client-ch
- Issues: https://github.com/morningzhang/redis-client-ch/issues
- npm.io page: https://npm.io/package/redis-client-ch

## Dependencies (4)

- [async](https://npm.io/package/async.md)
- [redis](https://npm.io/package/redis.md)
- [node-redis-failover](https://npm.io/package/node-redis-failover.md)
- [node-zookeeper-client](https://npm.io/package/node-zookeeper-client.md)

## 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.1.6 (latest) — 2014-12-18
- 0.1.5 — 2014-12-18
- 0.1.4 — 2014-12-16
- 0.1.3 — 2014-12-16
- 0.1.2 — 2014-11-10
- 0.1.1 — 2014-11-10
- 0.1.0 — 2014-11-07
- 0.0.9 — 2014-11-06
- 0.0.8 — 2014-11-05
- 0.0.7 — 2014-10-09
- 0.0.6 — 2014-09-15
- 0.0.5 — 2014-08-27
- 0.0.4 — 2014-08-04
- 0.0.3 — 2014-08-04
- 0.0.2 — 2014-08-04
- … 2 more at https://npm.io/package/redis-client-ch/versions

## README

use zookeeper mangage redis cluster and write to master and read from slave
-------
![Image text](http://raw.github.com/morningzhang/redis-client-ch/master/image/redis_ha_for_setting.png)


So ,we should have a ping server,install like this: <br/>
1.npm install -g node-redis-failover <br/>
2.cd to bin and  ./redis-failover -c ../examples/config.json <br/>

In the client , use like this:

```javascript

var YRedis=require('../index');
//four parameters，
//1.zookeeper config
//2.read commands.it can be empty array
//3.write command.it can be empty array
//4.key router function
var yredis=YRedis.getClient({servers:'172.20.0.47:2181',chroot:'/'},['sinter','mget','hgetall','ttl'],['set','incr','incrby','decrby','expire'],function(servers,command,sendArgs,sendCallback){
    var len=servers.length;
    if(sendArgs[1]){
        var key=sendArgs[0];
        var val=Buffer.byteLength(key, 'utf8')%len;
        console.log('=>',key,val);
        return val;
    }
    return 0;
});

yredis.on('ok',function(){
    yredis.SET('aaa',12,function(err,r){
        console.log(err,r);
    });
    yredis.decrby('aaa',-1,function(err,r){
        console.log(err,r);
    });
    yredis.addReadCommands('get');
    yredis.get('aaa',function(err,r){
        console.log(err,r);
    });
    yredis.SET('aa',12,function(err,r){
        console.log(err,r);
    });
    yredis.decrby('aa',-1,function(err,r){
        console.log(err,r);
    });
    yredis.get('aa',function(err,r){
        console.log(err,r);
    });

    //console.log(yredis.getServers());
    console.log(yredis.getMasterServer().name);
    var slaves= yredis.getSlaveServers()||[];

    slaves.forEach(function(slave){
        console.log(slave.name);
    });
});

```

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