lib/redis-sentinel/client.rb in redis-sentinel-1.4.1 vs lib/redis-sentinel/client.rb in redis-sentinel-1.4.2
- old
+ new
@@ -34,11 +34,11 @@
alias connect_without_sentinel connect
alias connect connect_with_sentinel
def sentinel?
- @master_name && @sentinels_options
+ !!(@master_name && @sentinels_options)
end
def auto_retry_with_timeout(&block)
deadline = @failover_reconnect_timeout.to_i + Time.now.to_f
begin
@@ -57,14 +57,14 @@
@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.host, :port => current_sentinel.port)
+ current_sentinel.sentinel("sentinels", @master_name).each do |response|
+ @sentinels_options << {:host => response[3], :port => response[5]}
+ end
+ @sentinels_options.uniq! {|h| h.values_at(:host, :port) }
end
def discover_master
while true
try_next_sentinel
@@ -77,12 +77,12 @@
refresh_sentinels_list
break
else
# A null reply
end
- rescue Redis::CommandError
- # An -IDONTKNOWN reply
+ rescue Redis::CommandError => e
+ raise unless e.message.include?("IDONTKNOW")
rescue Redis::CannotConnectError
# faile to connect to current sentinel server
end
end
end
@@ -118,17 +118,19 @@
def _parse_sentinel_options(options)
return if options.nil?
sentinel_options = []
- options.each do |sentinel_option|
- if sentinel_option.is_a?(Hash)
- sentinel_options << sentinel_option
+ options.each do |opts|
+ opts = opts[:url] if opts.is_a?(Hash) && opts.key?(:url)
+ case opts
+ when Hash
+ sentinel_options << opts
else
- uri = URI.parse(sentinel_option)
+ uri = URI.parse(opts)
sentinel_options << {
- host: uri.host,
- port: uri.port
+ host: uri.host,
+ port: uri.port
}
end
end
sentinel_options
end