redis-cluster-client
v1.0.1
Published
Automatic Redis Failover
Downloads
6
Readme
redis-cluster-client
Automatic Redis Failover
Installation
This module is installed via npm:
$ npm install redis-cluster-client
Example Usage
it.only('dynamic replace cluster client when cluster state changed', function(done) {
this.timeout(100000000);
var ClusterClient = require('redis-cluster-client');
var options = {zkservers:'localhost:6388,localhost:2181'};
var client = new ClusterClient(options);
client.init();
client.on('error', function(err) {
console.error('err:%s', err);
done();
});
// process.on("uncaughtException", function (error) {
// console.log('uncaught Exception:%j', error.stack);
// });
client.on('connect', function(client) {
var count = 0;
function batch() {
setTimeout(function() {
var c = client.clientFor(count);
console.log('%s:%d set %d %d', c.host, c.port, count, count);
client.set(count, count, function() {
count += 1;
if (count > 1000) {
console.log('exit.');
done();
}
console.log('count:%d', count);
process.nextTick(batch);
});
}, 1000);
}
batch();
});
});