Skip to content

Commit 26d3554

Browse files
authored
Merge pull request #176 from stanhu/sh-shutdown-redis-sentinel-connection
Close Redis Sentinel connection after resolving role
2 parents 4b6665a + 54de901 commit 26d3554

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/redis_client/sentinel_config.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ def each_sentinel
188188
if success
189189
@sentinel_configs.unshift(@sentinel_configs.delete(sentinel_config))
190190
end
191+
# Redis Sentinels may be configured to have a lower maxclients setting than
192+
# the Redis nodes. Close the connection to the Sentinel node to avoid using
193+
# a connection.
194+
sentinel_client.close
191195
end
192196
end
193197

test/sentinel/sentinel_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,11 @@ def test_sentinel_all_down
5050
end
5151

5252
class SentinelClientMock
53+
attr_reader :close_count
54+
5355
def initialize(responses)
5456
@responses = responses
57+
@close_count = 0
5558
end
5659

5760
def call(*args)
@@ -66,6 +69,10 @@ def call(*args)
6669
raise "Expected #{command.inspect}, got: #{args.inspect}"
6770
end
6871
end
72+
73+
def close
74+
@close_count += 1
75+
end
6976
end
7077

7178
def test_unknown_master
@@ -184,6 +191,7 @@ def test_successful_connection_refreshes_sentinels_list
184191
assert_equal Servers::SENTINELS.length + 1, @config.sentinels.length
185192
assert_equal new_sentinel_ip, @config.sentinels.last.host
186193
assert_equal new_sentinel_port, @config.sentinels.last.port
194+
assert_equal 1, sentinel_client_mock.close_count
187195
end
188196

189197
def test_sentinel_refresh_password
@@ -211,6 +219,8 @@ def test_sentinel_refresh_password
211219
@config.sentinels.each do |sentinel|
212220
refute_nil sentinel.password
213221
end
222+
223+
assert_equal 1, sentinel_client_mock.close_count
214224
end
215225

216226
def test_config_user_password_from_url_for_redis_master_replica_only

0 commit comments

Comments
 (0)