Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow master_name to be specified #630

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
32 changes: 32 additions & 0 deletions test/sentinel_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,38 @@ def test_sentinel_connection
assert_equal commands[:s2], []
end

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

commands = {
:s1 => [],
:s2 => [],
}

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|
RedisMock.start(handler.call(:s2)) do |s2_port|
sentinels[0][:port] = s1_port
sentinels[1][:port] = s2_port
redis = Redis.new(:url => "redis://master1", :master_name => 'named-master', :sentinels => sentinels, :role => :master)

assert redis.ping
end
end

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

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