Skip to content

Commit

Permalink
Merge remote-tracking branch 'greg/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
BookOfGreg committed Feb 6, 2017
2 parents 71efca9 + 27cb96e commit 721cbbd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/redis/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def initialize(options)

@sentinels = @options.delete(:sentinels).dup
@role = @options.fetch(:role, "master").to_s
@master = @options[:host]
@master = @options[:master_name] || @options[:host]
end

def check(client)
Expand Down
26 changes: 26 additions & 0 deletions test/sentinel_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,32 @@ def test_sentinel_role_mismatch
assert_match(/Instance role mismatch/, ex.message)
end

def test_sentinel_master_name
sentinels = [{:host => "127.0.0.1", :port => 26381}]

commands = {
:s1 => [],
}

handler = lambda do |id|
{
:sentinel => lambda do |command, *args|
commands[id] << [command, *args]
["127.0.0.1", "6381"]
end
}
end

RedisMock.start(handler.call(:s1)) do |s1_port|
sentinels[0][:port] = s1_port
redis = Redis.new(:url => "redis://master1", :sentinels => sentinels, :role => :master, :master_name => :new_master)

assert redis.ping
end

assert_equal commands[:s1], [%w[get-master-addr-by-name new_master]]
end

def test_sentinel_retries
sentinels = [{:host => "127.0.0.1", :port => 26381},
{:host => "127.0.0.1", :port => 26382}]
Expand Down

0 comments on commit 721cbbd

Please sign in to comment.