Skip to content
Redis master-slave client.
Find file
Latest commit 29a0aeb Mar 22, 2011 @ezkl ezkl Made minor README correction.


Redis Master Slave

Redis master-slave client for Ruby.

Writes are directed to a master Redis server, while reads are distributed round-robin across any number of slaves.


require 'redis_master_slave'

client ='redis.yml'))

client.set('a', 1)         # writes to master
client.get('a')            # reads from slaves, round-robin
client.master.get('a')     # reads directly from master
client.slaves[0].get('a')  # reads directly from first slave


The client can be configured in several ways.

Single configuration hash

Ideal for configuration via YAML file.

client ='redis.yml'))

Example YAML file:

  host: localhost
  port: 6379
  - host: localhost
    port: 6380
  - host: localhost
    port: 6381

URL strings

Specify the host and port for each Redis server as a URL string:

master_url = "redis://localhost:6379"
slave_urls = [
client =, slave_urls)

Separate master and slave configurations

Specify master and slave configurations as separate hashes:

master_config = {:host => 'localhost', :port => 6379}
slave_configs = []
  {:host => 'localhost', :port => 6380},
  {:host => 'localhost', :port => 6381},
client =, slave_configs)

Each configuration hash is passed directly to

Redis client objects

You can also pass your own Redis client objects:

master = => 'localhost', :port => 6379)
slave1 = => 'localhost', :port => 6380)
slave2 = => 'localhost', :port => 6381)
client =, [slave1, slave2])


  • Bug reports.
  • Source.
  • Patches: Fork on Github, send pull request.
    • Please include tests where practical.
    • Leave the version alone, or bump it in a separate commit.


Copyright (c) George Ogata. See LICENSE for details.

Something went wrong with that request. Please try again.