Skip to content
Merged
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
7 changes: 5 additions & 2 deletions lib/redis_client/sentinel_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def initialize(
username: url_config.username,
password: url_config.password,
db: url_config.db,
ssl: url_config.ssl?,
}.compact.merge(client_config)
name ||= url_config.host
end
Expand Down Expand Up @@ -66,6 +67,8 @@ def initialize(

client_config[:reconnect_attempts] ||= DEFAULT_RECONNECT_ATTEMPTS
@client_config = client_config || {}
@sentinel_client_config = @client_config.dup
@sentinel_client_config.delete(:ssl)
super(**client_config)
@sentinel_configs = sentinels_to_configs(sentinels)
end
Expand Down Expand Up @@ -133,9 +136,9 @@ def sentinels_to_configs(sentinels)
sentinels.map do |sentinel|
case sentinel
when String
Config.new(**@client_config, **@extra_config, url: sentinel)
Config.new(**@sentinel_client_config, **@extra_config, url: sentinel)
else
Config.new(**@client_config, **@extra_config, **sentinel)
Config.new(**@sentinel_client_config, **@extra_config, **sentinel)
end
end
end
Expand Down
22 changes: 22 additions & 0 deletions test/sentinel/sentinel_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,28 @@ def test_config_user_password_from_url_for_redis_master_replica_only
end
end

def test_config_ssl_from_rediss_url
sentinel_client_mock = SentinelClientMock.new([
[["SENTINEL", "get-master-addr-by-name", "cache"], [Servers::REDIS.host, Servers::REDIS.port.to_s]],
sentinel_refresh_command_mock,
])

config = new_config(url: "rediss://george:hunter2@cache/10", name: nil)

stub(config, :sentinel_client, ->(_config) { sentinel_client_mock }) do
assert_equal "hunter2", config.password
assert_equal "george", config.username
assert_equal 10, config.db
assert_predicate config, :ssl?
assert_equal [Servers::REDIS.host, Servers::REDIS.port], [config.host, config.port]

config.sentinels.each do |sentinel|
assert_nil sentinel.password
refute_predicate sentinel, :ssl?
end
end
end

def test_sentinel_shared_username_password
config = new_config(sentinel_username: "alice", sentinel_password: "superpassword")

Expand Down
Loading