chore: Ability to Remove password info from sentinel config (#4550)

Introduce the REDIS_SENTINEL_PASSWORD environment variable to customize the behaviour of sentinel passwords. 

Co-authored-by: EXT02D22861 <nusret.ozates@consultant.turkcell.com.tr>
Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
Nusret Ozates
2022-10-20 03:25:16 +03:00
committed by GitHub
parent 22d5703b92
commit 10d86fbb35
3 changed files with 57 additions and 12 deletions

View File

@@ -23,13 +23,20 @@ module Redis::Config
ENV.fetch('REDIS_SENTINELS', nil).presence
end
def sentinel_url_config(sentinel_url)
host, port = sentinel_url.split(':').map(&:strip)
sentinel_url_config = { host: host, port: port || DEFAULT_SENTINEL_PORT }
password = ENV.fetch('REDIS_SENTINEL_PASSWORD', base_config[:password])
sentinel_url_config[:password] = password if password.present?
sentinel_url_config
end
def sentinel_config
redis_sentinels = ENV.fetch('REDIS_SENTINELS', nil)
# expected format for REDIS_SENTINELS url string is host1:port1, host2:port2
sentinels = redis_sentinels.split(',').map do |sentinel_url|
host, port = sentinel_url.split(':').map(&:strip)
{ host: host, port: port.presence || DEFAULT_SENTINEL_PORT, password: base_config[:password] }
sentinel_url_config(sentinel_url)
end
# over-write redis url as redis://:<your-redis-password>@<master-name>/ when using sentinel