Skip to content

Commit e7168e6

Browse files
committed
Raise if no sentinels are available after 3 tries.
1 parent e5957f1 commit e7168e6

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

lib/redis/client.rb

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,7 @@ def _parse_driver(driver)
461461
end
462462

463463
class Connector
464-
attr_reader :logger
465464
def initialize(options)
466-
@logger = options[:logger]
467465
@options = options
468466
end
469467

@@ -514,28 +512,28 @@ def resolve
514512
end
515513

516514
def sentinel_detect
517-
@sentinels.each do |sentinel|
518-
client = Client.new(:host => sentinel[:host], :port => sentinel[:port], :timeout => 0.3)
519-
520-
begin
521-
if result = yield(client)
522-
# This sentinel responded. Make sure we ask it first next time.
523-
@sentinels.delete(sentinel)
524-
@sentinels.unshift(sentinel)
525-
526-
return result
515+
3.times do
516+
@sentinels.each do |sentinel|
517+
client = Client.new(:host => sentinel[:host], :port => sentinel[:port], :timeout => 0.3)
518+
519+
begin
520+
if result = yield(client)
521+
# This sentinel responded. Make sure we ask it first next time.
522+
@sentinels.delete(sentinel)
523+
@sentinels.unshift(sentinel)
524+
525+
return result
526+
end
527+
rescue CannotConnectError
528+
ensure
529+
client.disconnect
527530
end
528-
rescue CannotConnectError
529-
if logger
530-
msg = "[Redis] Could not connect to sentinel #{sentinel[:host]}:#{sentinel[:port]}"
531-
logger.debug(msg)
532-
end
533-
ensure
534-
client.disconnect
535531
end
532+
533+
sleep(0.3)
536534
end
537535

538-
return nil
536+
raise CannotConnectError, "No sentinels available."
539537
end
540538

541539
def resolve_master

0 commit comments

Comments
 (0)