Class: RedisWmrs::SlaveClient
- Inherits:
-
Redis::Client
- Object
- Redis::Client
- RedisWmrs::SlaveClient
- Defined in:
- lib/redis_wmrs/slave_client.rb
Constant Summary collapse
- MASTER_PRIORITY =
0
Class Method Summary collapse
Instance Method Summary collapse
-
#connect ⇒ Object
override Redis::Client#connect overwritten by redis-sentinel github.com/flyerhzm/redis-sentinel/blob/master/lib/redis-sentinel/client.rb#L24.
- #discover_slave ⇒ Object
Class Method Details
.ip_and_hostnames ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/redis_wmrs/slave_client.rb', line 85 def self.ip_and_hostnames unless @my_hostname @my_hostname = Socket::gethostname rescue nil @my_ip = IPSocket::getaddress(@my_hostname) rescue nil end return @my_hostname, @my_ip end |
Instance Method Details
#connect ⇒ Object
override Redis::Client#connect overwritten by redis-sentinel github.com/flyerhzm/redis-sentinel/blob/master/lib/redis-sentinel/client.rb#L24
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/redis_wmrs/slave_client.rb', line 9 def connect if sentinel? auto_retry_with_timeout do discover_slave begin connect_without_sentinel rescue => e @failed ||= [] f = "#{@options[:host]}:#{@options[:port]}" @failed.delete(f) @failed.push(f) # 必ず末尾に追加する raise e else @failed.delete("#{@options[:host]}:#{@options[:port]}") if @failed end end else connect_without_sentinel end end |
#discover_slave ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/redis_wmrs/slave_client.rb', line 30 def discover_slave while true try_next_sentinel host_attrs = fetch_slaves host_attrs.each do |attrs| begin host, port = attrs["ip"], attrs["port"] if host && port # An ip:port pair @options.merge!(:host => host, :port => port.to_i, :password => @master_password) refresh_sentinels_list return else # A null reply end rescue Redis::CommandError => e raise unless e..include?("IDONTKNOW") rescue Redis::CannotConnectError # faile to connect to current sentinel server end end end end |