lib/redis-sentinel/client.rb in redis-sentinel-1.4.0 vs lib/redis-sentinel/client.rb in redis-sentinel-1.4.1
- old
+ new
@@ -3,11 +3,10 @@
class Redis::Client
DEFAULT_FAILOVER_RECONNECT_WAIT_SECONDS = 0.1
class_eval do
attr_reader :current_sentinel
- attr_reader :current_sentinel_options
def initialize_with_sentinel(options={})
options = options.dup # Don't touch my options
@master_name = fetch_option(options, :master_name)
@master_password = fetch_option(options, :master_password)
@@ -51,23 +50,20 @@
end
end
def try_next_sentinel
sentinel_options = @sentinels_options.shift
- if sentinel_options
- @logger.debug "Trying next sentinel: #{sentinel_options[:host]}:#{sentinel_options[:port]}" if @logger && @logger.debug?
- @current_sentinel_options = sentinel_options
- @current_sentinel = Redis.new sentinel_options
- else
- raise Redis::CannotConnectError
- end
+ @sentinels_options.push sentinel_options
+
+ @logger.debug "Trying next sentinel: #{sentinel_options[:host]}:#{sentinel_options[:port]}" if @logger && @logger.debug?
+ @current_sentinel = Redis.new sentinel_options
end
def refresh_sentinels_list
responses = current_sentinel.sentinel("sentinels", @master_name)
@sentinels_options = responses.map do |response|
{:host => response[3], :port => response[5]}
- end.unshift(:host => current_sentinel_options[:host], :port => current_sentinel_options[:port])
+ end.unshift(:host => current_sentinel.host, :port => current_sentinel.port)
end
def discover_master
while true
try_next_sentinel