multi-redis
A simple wrapper around the node_redis
and node-hashring
modules to allow for an easy way to use consistent hashing to distribute to
multiple redises.
Example
//// Pass in array of redis objects of the form...// [// {// "host": "127.0.0.1",// "port": 6379// }// ]// into this function//var multiRedis = ;var key = 'jcrugzz/test';//// Return a redis client based on the consistent hasing of hashring//var client = multiRedis; //// Now we have a standard `node_redis` client//client;
API
var multiRedis = require('multi-redis')(redises)
Constructor -> Instantiates a multiRedis instance that sets up the array of redis clients
var client = multRedis.client(key)
Retrieves the correct client based on key given using the consistent hashing of
node-hashring
multiRedis.end()
Calls redis.end()
for all of the underlying redis clients instantiated by the
constructor
multiRedis.on('error', function (err) { /* Handle me however you please */ })
This is how you handle the errors that are emitted from the underlying
redis
. Useful for logging purposes as the node_redis
library handles reconnections for you but stil emits ECONNREFUSED
errors when
the server is not reachable.
License
MIT