Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Redis master-slave client.
Ruby
branch: master

This branch is 28 commits ahead of oggy:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
test
.gitignore
CHANGELOG
Gemfile
LICENSE
README.markdown
Rakefile
redis_master_slave.gemspec

README.markdown

Redis Master Slave

Redis master-slave client for Ruby, currently only implemented for failover.

Usage

require 'redis_master_slave'

client = RedisMasterSlave.new(YAML.load_file('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

Configuration

The client can be configured in several ways.

Single configuration hash

Ideal for configuration via YAML file.

client = RedisMasterSlave.new(YAML.load_file('redis.yml'))

Example YAML file:

development:
  master:
      host: localhost
      port: 6379
  slaves:
      - host: localhost
        port: 6380
      - host: localhost
        port: 6381
production:
  master:
      host: redishost1
      port: 6379
  slaves:
      - host: redishost2
        port: 6380
      - host: redishost3
        port: 6381

URL strings

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

master_url = "redis://localhost:6379"
slave_urls = [
  "redis://localhost:6380",
  "redis://localhost:6381",
]
client = RedisMasterSlave.new(master_urls, 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 = RedisMasterSlave.new(master_config, slave_configs)

Each configuration hash is passed directly to Redis.new.

Redis client objects

You can also pass your own Redis client objects:

master = Redis.new(:host => 'localhost', :port => 6379)
slave1 = Redis.new(:host => 'localhost', :port => 6380)
slave2 = Redis.new(:host => 'localhost', :port => 6381)
client = RedisMasterSlave.new(master, [slave1, slave2])

Contributing

  • 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

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

Something went wrong with that request. Please try again.