0.1.0 • Published 10 years ago

redis-clustering-client v0.1.0

Weekly downloads
4
License
ISC
Repository
github
Last release
10 years ago

redis-clustering-client

A client for communicating with a Redis Cluster via the cluster's Sentinel applications.

This module abstracts away the concept of a cluster to allow users to connect to the cluster master regardless of any failovers that have occurred since the last connection.
You also have the option of connecting to a random slave of the cluster as well.

Usage:

A simple example:

  var Sentinel = require('./redis-sentinel.js');

  // Initialize to use all known Sentinels
  Sentinel.init('mymaster', 
  [
    { host:'localhost', port:26379},
    { host:'192.168.1.1', port:26379},
    { host:'anotherHost', port:26380}
  ], ready);


  function ready(err) {
    if (err) {
      console.log('ERROR: ' + err);
      return;
    }

    // Connect to the cluster master and set a value
    Sentinel.command('set', ['clustering', 'is cool!']);

    // Connect to a random slave and get a hash value
    Sentinel.command('hget', ['fuster', 'cluck'], function(err, resp) {
      if (err) {
        console.log('ERROR: ' + err);
        return;
      }
      console.log(resp);
    }, true);
  }

API:

###cluster.init(cluster, sentinelArray, callback) Provide an ordered array of sentinels to use for connections. A connection to the reported Master Redis server is also established as a check.

  • cluster: the name of the Redis Cluster in sentinel.conf (default: mymaster)
  • sentinelArray: an array of objects describing each Redis Sentinel to attempt a connection with.
    Example (default):
    [{host:"localhost", port:26379}]
  • callback([err]): called when test connection to master is completed or an error occurs

###cluster.command(cmd, args, callback, slave) Send a Redis command to the cluster master (or slave if slave == true) and receive the response.

  • cmd: redis command to execute
  • args: array of arguments to the command
  • callback(err, [res]): response from the redis server
  • slave: boolean - if true send command to a random slave

Defaults:

  • cluster: mymaster
  • sentinels:
    [{host:"localhost", port:26389}]
0.1.0

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago

0.0.0

10 years ago