redis-cluster-client

Automatic Redis Failover

redis-cluster-client

Automatic Redis Failover

This module is installed via npm:

$ npm install redis-cluster-client
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();
    });
});