Skip to content
Redis Cluster client for Ruby
Ruby Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci Add middleware feature (#7) Jun 7, 2018
lib add circuit breaker (#11) Jul 1, 2019
spec add circuit breaker (#11) Jul 1, 2019
.editorconfig init files Mar 13, 2017
.gitignore add ignore for .circleci/tmp Apr 21, 2017
.rubocop.yml Add middleware feature (#7) Jun 7, 2018
.ruby-version [SRE-850] Exclue slave instance in LOADING state from client candidate ( Jul 17, 2018
Gemfile make circleci green Mar 22, 2017
Gemfile.lock [SRE-850] Exclue slave instance in LOADING state from client candidate ( Jul 17, 2018
LICENSE Add LICENSE file (#6) Jun 5, 2018 expose client in middleware (#8) Jun 7, 2018
Rakefile handle server down case Mar 22, 2017
redis-cluster.gemspec update readme May 18, 2017


CircleCI Coverage


redis-cluster is redis cluster client for ruby that support pipelining.


SRE Bukalapak



Onboarding and Development Guide

Getting started

  1. Install redis-cluster

    gem install 'redis-cluster'
  2. Start irb. This command will start a redis-cluster client from seed servers.

    seed = ['', '']
    redis =
                              redis_opts: { timeout: 5, connect_timeout: 1 },
                              cluster_opts: { force_cluster: false, read_mode: :master_slave, silent: true, logger: }
    redis.middlewares.register(:commit) do |*args, &block|
      puts "this is RedisCluster middlewares"

Development Guide

  1. You need rvm and bundler to test. See here to install rvm. And run these commands to install bundler and other dependencies

    gem install bundler
    bundle install
  2. You also need redis binary. See here to install redis

  3. Fork this repo

  4. Make your change and it's test.

    vim lib/**.rb
    vim spec/**_spec.rb
  5. Optionally, run the test in your local

    rake # run all test and lint
  6. Commit and push your change to upstream

    git commit -m "message"
    git push # add "--set-upstream branch_name" after "git push" if you haven't set the upstream
  7. Open pull request in Github

  8. If test in CI is success, ask someone to review your code.

  9. If review is passed, your pull request can be merged.



Option for Redis::Client instance. Set timeout, ssl, etc here.


Option for RedisCluster.

  • force_cluster: if true, RedisCluster will only work on clustered Redis or otherwise can also work on standalone Redis. The default value is false.
  • read_mode: for read command, RedisClient can try to read from slave if specified. Supported option is :master(default), :slave, and :master_slave.
  • silent: whether or not RedisCluster will raise error.
  • logger: if specified. RedisCluster will log all of RedisCluster errors here.


Middlewares are hooks that RedisCluster provide to observe RedisCluster events. To register a middlewares, provide callable object (object that respond to call) or give block in register method. Middlewares must give block result as return value.

# Using callable
class Callable
  def call
    start =
  rescue StandardError => e
    raise e
    Metrics.publish(elapsed_time: - start)

# Using proc
redis.middlewares.register(:commit) do |*args, &block|
    res =
  rescue StandardError => e
    raise e

Currently there are 3 events that RedisCluster publish.

  • :commit RedisCluster will fire :commit events when RedisCluster::Client call redis server. It give RedisCluster::Client as arguments.
    redis.middlewares.register(:commit) do |client, &block|
      puts 'this is :commit events'
      puts "client url: #{client.url}"
      puts "first command: #{client.queue.first.first}"
      puts "last command: #{client.queue.last.first}"
  • :call This events is fired when command is issued in RedisCluster client before any load balancing is done. It give RedisCluster and RedisCluster#call arguments as arguments
    redis.middlewares.register(:call) do |client, keys, command, opts = {}, &block|
      puts "keys to load balance: #{keys}"
      puts "redis command: #{command.first}"
      puts "in pipelined?: #{client.pipelined?}"
    # Output:
    #   keys to load balance: something
    #   redis command: get
  • :pipelined This events is fired when pipelined method is called from redis client. It does give RedisCluster as arguments
    redis.middlewares.register(:pipelined) do |client, &block|
      puts 'pipelined is called'


All multi keys operation, cluster command, multi-exec, and some commands are not supported.


Can be used with same interface as standalone redis client. See redis pipeline


You can’t perform that action at this time.