Sha256: d92888d6efbf9e20f832009fa4cc1ca851e1a4ebfb5fbac7c5599415010bf05d

Contents?: true

Size: 1023 Bytes

Versions: 24

Compression:

Stored size: 1023 Bytes

Contents

require 'redis'

# This example creates a master-slave setup with a sentinel, then connects to
# it and sends write commands in a loop.
#
# After 30 seconds, the master dies. You will be able to see how a new master
# is elected and things continue to work as if nothing happened.
#
# To run this example:
#
#   $ ruby -I./lib examples/sentinel.rb
#

at_exit do
  begin
    Process.kill(:INT, $redises)
  rescue Errno::ESRCH
  end

  Process.waitall
end

$redises = spawn("examples/sentinel/start")

Sentinels = [{:host => "127.0.0.1", :port => 26379},
             {:host => "127.0.0.1", :port => 26380}]
r = Redis.new(:url => "redis://master1", :sentinels => Sentinels, :role => :master)

# Set keys into a loop.
#
# The example traps errors so that you can actually try to failover while
# running the script to see redis-rb reconfiguring.
(0..1000000).each{|i|
    begin
        r.set(i,i)
        $stdout.write("SET (#{i} times)\n") if i % 100 == 0
    rescue => e
        $stdout.write("E")
    end
    sleep(0.01)
}

Version data entries

24 entries across 23 versions & 7 rubygems

Version Path
finsync_redis-3.3.5 examples/sentinel.rb
redis-4.0.3 examples/sentinel.rb
redis-4.1.0.beta1 examples/sentinel.rb
redis-4.0.2 examples/sentinel.rb
redis-3.3.5 examples/sentinel.rb
redis-4.0.1 examples/sentinel.rb
redis-4.0.0 examples/sentinel.rb
logstash-filter-cache-redis-0.3.1 vendor/bundle/jruby/1.9/gems/redis-3.3.3/examples/sentinel.rb
logstash-filter-cache-redis-0.3.0 vendor/bundle/jruby/1.9/gems/redis-3.3.3/examples/sentinel.rb
logstash-filter-cache-redis-0.2.0 vendor/bundle/jruby/1.9/gems/redis-3.3.3/examples/sentinel.rb
logstash-filter-cache-redis-0.1.0 vendor/bundle/jruby/1.9/gems/redis-3.3.3/examples/sentinel.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/redis-3.3.3/examples/sentinel.rb
redis-3.3.3 examples/sentinel.rb
abaci-0.3.0 vendor/bundle/gems/redis-3.3.2/examples/sentinel.rb
abaci-0.3.0 vendor/bundle/gems/redis-3.3.1/examples/sentinel.rb
redis-4.0.0.rc1 examples/sentinel.rb
redis-3.3.2 examples/sentinel.rb
redis-3.3.1 examples/sentinel.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/redis-3.3.0/examples/sentinel.rb
redis-3.3.0 examples/sentinel.rb