Skip to content
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
1 change: 1 addition & 0 deletions lib/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def self.current=(redis)
# @option options [Boolean] :inherit_socket (false) Whether to use socket in forked process or not
# @option options [Array] :sentinels List of sentinels to contact
# @option options [Symbol] :role (:master) Role to fetch via Sentinel, either `:master` or `:slave`
# @option options [String] :master_name Master group name according to the `monitor` line in Sentinel config
#
# @return [Redis] a new client instance
def initialize(options = {})
Expand Down
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