Project

redis_wmrs

0.0
No commit activity in last 3 years
No release in over 3 years
redis client to write to master node and read from slave node
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
>= 0
>= 0
>= 0

Runtime

~> 3.0.0
 Project Readme

redis_wmrs

There are some client libraries for redis on ruby.

https://rubygems.org/search?query=redis

redis-sentinel works well with redis and redis sentinel cluster. But it look up master node only. Even if there are a lot of redis-servers, each redis client connect to only one redis-server.

Write master, Read slave

If you want to distribute the accesses from redis clients to master node, your application should read data from slave node and write to master node.

RedisWmrs makes 2 redis-sentinel clients look 1 client.

Overview

before using redis_wmrs

just only using redis-sentinel

GET and SET commands are sent to one master redis server only.

after using redis_wmrs

GET commands are sent to each local redis server. SET commands are sent to one master redis server only.

Performance

We made a benchmark tool redis_cluster_cache_benchmark for cache with a master-slave cluster.

see a result for more detail

Installation

Add this line to your application's Gemfile:

gem 'redis_wmrs'

And then execute:

$ bundle

Or install it yourself as:

$ gem install redis_wmrs

Usage

Almost same as redis or redis-sentinel, but class name is not just Redis but RedisWmrs.


redis = RedisWmrs.new(
  :master_name => "sentinel_master",
  :sentinels => [
    {:host => "redis01", :port => 26379},
    {:host => "redis02", :port => 26379},
    {:host => "redis03", :port => 26379}
  ])

i = -1
while true
  i += 1
  i = 0 if i > 10
  redis.set("foo", Time.now.to_s) if i == 0

  header = "[#{Time.now.to_s}] sentinel:#{redis.client.current_sentinel.client.location} redis:#{redis.client.location}"
  begin
    puts "#{header} #{redis.get 'foo'}"
  rescue => e
    puts "#{header} [#{e.class.name}]: #{e.message}"
  end
  sleep 1
end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request