• Stars
    star
    107
  • Rank 323,587 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 11 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Redis Cluster client for Node.js

redis-clustr

Dependencies Join the chat at https://gitter.im/gosquared/redis-clustr

NPM

This module is a relatively thin wrapper around the node redis client to enable use of Redis Cluster. It tries to be as unobtrusive as possible - mimicing the behaviour of the node_redis client.

Usage

var RedisClustr = require('redis-clustr');

var redis = new RedisClustr({
  servers: [
    {
      host: '127.0.0.1',
      port: 7000
    }
  ]
});

redis.set('key', 'value');

Servers

Servers in the cluster will be automatically connected to (via the response of cluster slots). Of course, to allow discovery there must be at least one server specified in the configuration.

Client creation

By default, clients will be created using Redis.createClient(port, host). This can be overridden by providing a function which must return a node_redis client. Clients are cached so only one connection will be made to each server.

var RedisClustr = require('redis-clustr');
var RedisClient = require('redis');
var redis = new RedisClustr({
  servers: [...],
  createClient: function(port, host) {
    // this is the default behaviour
    return RedisClient.createClient(port, host);
  }
});

Options

var RedisClustr = require('redis-clustr');
var redis = new RedisClustr({
  servers: [...],
  slotInterval: 1000, // default: none. Interval to repeatedly re-fetch cluster slot configuration
  maxQueueLength: 100, // default: no limit. Maximum length of the getSlots queue (basically number of commands that can be queued whilst connecting to the cluster)
  queueShift: false, // default: true. Whether to shift the getSlots callback queue when it's at max length (error oldest callback), or to error on the new callback
  wait: 5000, // default: no timeout. Max time to wait to connect to cluster before sending an error to all getSlots callbacks
  slaves: 'share', // default: 'never'. How to direct readOnly commands: 'never' to use masters only, 'share' to distribute between masters and slaves or 'always' to  only use slaves (if available)
  createClient: function(port, host, options) {
    return require('redis').createClient(port, host, options);
  }, // default: redis.createClient. Function used to connect to redis, called with arguments above
  redisOptions: {
    // options passed to the node_redis client https://github.com/NodeRedis/node_redis#options-is-an-object-with-the-following-possible-properties
    retry_max_delay: 500
    // etc
  }
});

Supported functionality

Slot reallocation

Supported - when a response is given with a MOVED error, we will immediately re-issue the command on the other server and run another cluster slots to get the new slot allocations. ASK redirection is also supported - we wil re-issue the command without updating the slots. TRYAGAIN responses will be retried automatically.

Multi / Exec (Batch)

Multi commands are supported but treated as a batch of commands (not an actual multi) and the response is recreated in the original order. Commands are grouped by node and sent as node_redis batches

Multi-key commands (del, mget and mset)

Multi-key commands are also supported and will be split into individual commands (using a batch) then have the response recreated. Only del, mget and mset are supported at the moment.

Pub/Sub

Pub/Sub is fully supported. When subscribe is used, a new client will be created (connected to a random node). This client is shared for all subscriptions.

var RedisClustr = require('redis-clustr');
var redis = new RedisClustr({...});

redis.on('message', function(channel, message) { /* ... */ });

redis.subscribe('my-channel', function(err) {
  redis.publish('my-channel', 'have a lovely day!');
});

Errors

Just like node_redis, listen to the error event to stop your application from crashing due to errors. Redis Clustr automatically intercepts connection errors and will try to reconnect to the server.

More Repositories

1

flags

GoSquared's flag icon set
Makefile
498
star
2

mmdb-reader

Node.js reader for MaxMind DB (.mmdb) files for IP address data
JavaScript
46
star
3

convoy

Redis-backed unique job queueing
JavaScript
33
star
4

optim

S3 + Lambda + Imagemin = win
JavaScript
31
star
5

clutch

Makes your Node.js server run as a cluster of processes, without the mess
JavaScript
27
star
6

flutter

Twitter OAuth module for Node.js
JavaScript
23
star
7

speed-date

Format dates super-fast in JavaScript
JavaScript
22
star
8

twitter-oauth

Use twitter 1.1 API through OAuth with ease.
JavaScript
22
star
9

stash

Distributed cache using Redis and process memory with TTL expiry and LRU pruning
JavaScript
19
star
10

node-gosquared

GoSquared for your Node.JS application
JavaScript
17
star
11

aws-elasticsearch-js

Use elasticsearch-js with Amazon ES
JavaScript
14
star
12

graphite-cookbook

Graphite via Chef
Ruby
13
star
13

gosquared-ios

Live Chat SDK for integrating the GoSquared chat client in your iOS app.
Objective-C
13
star
14

graphite-metric

If you're sending data to Graphite from Ruby, GraphiteMetric will help you get it in the right format.
Ruby
12
star
15

ipcheck

Super-efficient Node.js module to parse and check if an IP address is in a CIDR block. IPv4 and IPv6 supported.
JavaScript
11
star
16

php-sdk

SDK for integrating GoSquared Analytics into your PHP application
PHP
10
star
17

rush

LRU cache for busy apps in a hurry
JavaScript
9
star
18

ruby-client

GoSquared Ruby Client
Ruby
9
star
19

gosquared-jquery

jQuery Plugin for interacting with GoSquared's API and event tracking
JavaScript
8
star
20

gosquared-api-php-sdk

This SDK is deprecated. Use new SDK:
PHP
7
star
21

ganglia-cookbook

Chef cookbook for Ganglia
Ruby
7
star
22

tql

Node.js module to create mock MySQL databases based on your schema and makes it easy to insert test data
JavaScript
6
star
23

gosquared-admin-api-php-sdk

PHP SDK for the GoSquared admin API
PHP
5
star
24

gosquared-wordpress-plugin

Source files for the official GoSquared Wordpress Plugin
PHP
5
star
25

hyacinth

A token bucket based rate limiter
JavaScript
4
star
26

mysql-cookbook

Chef cookbook for MySQL
Ruby
4
star
27

anchorman

Distributed message broadcasting using redis
JavaScript
3
star
28

logs2

Cloudwatch logger
TypeScript
3
star
29

phantomjs-cookbook

phantomjs via chef for debian distros
Ruby
3
star
30

php-cookbook

Compile PHP from source, as an apache module or with php-fpm for nginx. Or just set up some php modules.
Ruby
3
star
31

gosquared-rails

Quickly and easily install GoSquared Live Chat, Analytics, and People in your Rails app
Ruby
2
star
32

resque-pigeon

Creates resque jobs from messages and then it delivers them
Ruby
2
star
33

htpasswd-cookbook

Chef cookbook for self-contained htpasswd support (depends only on openssl)
Ruby
2
star
34

check

Redis backed service for monitoring metric data streams against pre-defined thresholds
Ruby
2
star
35

rabbitmq-cookbook

Chef cookbook for RabbitMQ, includes HA clustering.
Ruby
2
star
36

seif

Central datastore and API for hosts, services (with owners) and secrets. Ships with an Angular JS admin UI.
Ruby
2
star
37

nvm-cookbook

Chef cookbook for installing and managing nvm on Ubuntu
Ruby
1
star
38

apache2-cookbook

Chef cookbook for Apache2
Ruby
1
star
39

elasticsearch-cookbook

Chef cookbook for elasticsearch, tested on Ubuntu
Ruby
1
star
40

woocommerce-plugin

GoSquared WooCommerce plugin
PHP
1
star
41

redis-scripts

Collection of Redis scripts packaged as a node module
JavaScript
1
star
42

chef-nvm

Chef Cookbook to install NVM
Ruby
1
star
43

python-cookbook

Python via Chef
Ruby
1
star