Skip to content

Commit 721cbbd

Browse files
committed
Merge remote-tracking branch 'greg/master'
2 parents 71efca9 + 27cb96e commit 721cbbd

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

lib/redis/client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ def initialize(options)
509509

510510
@sentinels = @options.delete(:sentinels).dup
511511
@role = @options.fetch(:role, "master").to_s
512-
@master = @options[:host]
512+
@master = @options[:master_name] || @options[:host]
513513
end
514514

515515
def check(client)

test/sentinel_test.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,32 @@ def test_sentinel_role_mismatch
196196
assert_match(/Instance role mismatch/, ex.message)
197197
end
198198

199+
def test_sentinel_master_name
200+
sentinels = [{:host => "127.0.0.1", :port => 26381}]
201+
202+
commands = {
203+
:s1 => [],
204+
}
205+
206+
handler = lambda do |id|
207+
{
208+
:sentinel => lambda do |command, *args|
209+
commands[id] << [command, *args]
210+
["127.0.0.1", "6381"]
211+
end
212+
}
213+
end
214+
215+
RedisMock.start(handler.call(:s1)) do |s1_port|
216+
sentinels[0][:port] = s1_port
217+
redis = Redis.new(:url => "redis://master1", :sentinels => sentinels, :role => :master, :master_name => :new_master)
218+
219+
assert redis.ping
220+
end
221+
222+
assert_equal commands[:s1], [%w[get-master-addr-by-name new_master]]
223+
end
224+
199225
def test_sentinel_retries
200226
sentinels = [{:host => "127.0.0.1", :port => 26381},
201227
{:host => "127.0.0.1", :port => 26382}]

0 commit comments

Comments
 (0)