Skip to content

Commit 021af54

Browse files
committed
Fix sentinel when using a database other than 0.
1 parent 42adf30 commit 021af54

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/redis/client.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,10 @@ class Sentinel < Connector
488488
def initialize(options)
489489
super(options)
490490

491+
@options[:password] = DEFAULTS.fetch(:password)
492+
@options[:db] = DEFAULTS.fetch(:db)
493+
491494
@sentinels = @options.delete(:sentinels).dup
492-
@options.delete(:password)
493495
@role = @options.fetch(:role, "master").to_s
494496
@master = @options[:host]
495497
end

test/sentinel_test.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def test_sentinel_failover_prioritize_healthy_sentinel
110110
assert_equal commands[:s2], [%w[get-master-addr-by-name master1], %w[get-master-addr-by-name master1]]
111111
end
112112

113-
def test_sentinel_with_auth
113+
def test_sentinel_with_non_sentinel_options
114114
sentinels = [{:host => "127.0.0.1", :port => 26381}]
115115

116116
commands = {
@@ -123,6 +123,10 @@ def test_sentinel_with_auth
123123
commands[:s1] << ["auth", pass]
124124
"-ERR unknown command 'auth'"
125125
end,
126+
:select => lambda do |db|
127+
commands[:s1] << ["select", db]
128+
"-ERR unknown command 'select'"
129+
end,
126130
:sentinel => lambda do |command, *args|
127131
commands[:s1] << [command, *args]
128132
["127.0.0.1", "6382"]
@@ -142,7 +146,7 @@ def test_sentinel_with_auth
142146

143147
RedisMock.start(master, {}, 6382) do
144148
RedisMock.start(sentinel, {}, 26381) do
145-
redis = Redis.new(:url => "redis://:foo@master1", :sentinels => sentinels, :role => :master)
149+
redis = Redis.new(:url => "redis://:foo@master1/15", :sentinels => sentinels, :role => :master)
146150

147151
assert redis.ping
148152
end

0 commit comments

Comments
 (0)