lib/redis-sentinel/client.rb in redis-sentinel-1.1.3 vs lib/redis-sentinel/client.rb in redis-sentinel-1.1.4
- old
+ new
@@ -47,11 +47,11 @@
end
def try_next_sentinel
@sentinels << @sentinels.shift
if @logger && @logger.debug?
- @logger.debug? "Trying next sentinel: #{@sentinels[0][:host]}:#{@sentinels[0][:port]}"
+ @logger.debug "Trying next sentinel: #{@sentinels[0][:host]}:#{@sentinels[0][:port]}"
end
return @sentinels[0]
end
def discover_master
@@ -61,15 +61,20 @@
begin
host, port = sentinel.sentinel("get-master-addr-by-name", @master_name)
if !host && !port
raise Redis::ConnectionError.new("No master named: #{@master_name}")
end
- @options.merge!(:host => host, :port => port.to_i)
-
+ is_down, runid = sentinel.sentinel("is-master-down-by-addr", host, port)
break
rescue Redis::CannotConnectError
try_next_sentinel
end
+ end
+
+ if is_down == "1" || runid == '?'
+ raise Redis::CannotConnectError.new("The master: #{@master_name} is currently not available.")
+ else
+ @options.merge!(:host => host, :port => port.to_i)
end
end
private