redis-cluster-client

1.0.1 • Public • Published

redis-failover-in-nodejs

Automatic Redis Failover

build status

Installation

This module is installed via npm:

$ npm install redis-failover-node

Example Usage

var expect = require('expect.js'),
    ClusterClient = require('redis-cluster-client');
 
describe('testcase for cluster client', function() {
    it('client for', function(done) {
        this.timeout(100000000);
        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();
        });
 
        client.on('connect', function(client) {
            var count = 0;
            function batch() {
                setTimeout(function() {
                    client.clientFor(count, function(err, c) {
                        // console.log('%s:%d set %d %d', c.host, c.port, count, count);
                        c.set(count, count, function() {
                            count += 1;
                            if (count > 1000) {
                                console.log('exit.');
                                done();
                            }
                            console.log('count:%d', count);
                            c.release();
                            process.nextTick(batch);
                        });
                    });
                }, 1000);
            }
            batch();
        });
    });
 
 
 
    it.only('cluster command', function(done) {
        this.timeout(100000000);
        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();
        });
        client.on('connect', function(client) {
            var count = 0;
            function batch() {
                setTimeout(function() {
                    client.set(count, count, function() {
                            count += 1;
                            if (count > 1000) {
                                console.log('exit.');
                                done();
                            }
                            console.log('count:%d', count);
                            process.nextTick(batch);
                    });
                }, 1000);
            }
            batch();
        });
    });
 
    process.on("uncaughtException", function (error) {
        console.log('uncaught Exception:%j', error.stack);
    });
 
});

Readme

Keywords

none

Package Sidebar

Install

npm i redis-cluster-client

Weekly Downloads

0

Version

1.0.1

License

BSD-3-Clause

Last publish

Collaborators

  • piaolingxue