Skip to content

Commit 769efea

Browse files
badboydjanowski
authored andcommitted
Pass on all options to Sentinels and fetched nodes
1 parent c6963ec commit 769efea

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

lib/redis/client.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,9 @@ def establish_connection
317317
server = @connector.resolve.dup
318318

319319
@options[:host] = server[:host]
320-
@options[:port] = server[:port]
320+
@options[:port] = Integer(server[:port])
321321

322-
@connection = @options[:driver].connect(server)
322+
@connection = @options[:driver].connect(@options)
323323
@pending_reads = 0
324324
rescue TimeoutError,
325325
Errno::ECONNREFUSED,
@@ -470,7 +470,7 @@ def _parse_driver(driver)
470470

471471
class Connector
472472
def initialize(options)
473-
@options = options
473+
@options = options.dup
474474
end
475475

476476
def resolve
@@ -484,9 +484,9 @@ class Sentinel < Connector
484484
def initialize(options)
485485
super(options)
486486

487-
@sentinels = options.fetch(:sentinels).dup
488-
@role = options.fetch(:role, "master").to_s
489-
@master = options[:host]
487+
@sentinels = @options.delete(:sentinels).dup
488+
@role = @options.fetch(:role, "master").to_s
489+
@master = @options[:host]
490490
end
491491

492492
def check(client)
@@ -521,7 +521,10 @@ def resolve
521521

522522
def sentinel_detect
523523
@sentinels.each do |sentinel|
524-
client = Client.new(:host => sentinel[:host], :port => sentinel[:port], :timeout => 0.3)
524+
client = Client.new(@options.merge({
525+
:host => sentinel[:host],
526+
:port => sentinel[:port]
527+
}))
525528

526529
begin
527530
if result = yield(client)

lib/redis/connection/hiredis.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ class Hiredis
99

1010
def self.connect(config)
1111
connection = ::Hiredis::Connection.new
12+
connect_timeout = (config.fetch(:connect_timeout, 0) * 1_000_000).to_i
1213

1314
if config[:scheme] == "unix"
14-
connection.connect_unix(config[:path], Integer(config[:connect_timeout] * 1_000_000))
15+
connection.connect_unix(config[:path], connect_timeout)
1516
else
16-
connection.connect(config[:host], config[:port], Integer(config[:connect_timeout] * 1_000_000))
17+
connection.connect(config[:host], config[:port], connect_timeout)
1718
end
1819

1920
instance = new(connection)

0 commit comments

Comments
 (0)