leave out @ in redis+sentine url when no username/password is provided

This commit is contained in:
Jan Kessler 2025-04-03 08:24:24 +02:00
parent 35ea29b184
commit 257ca45456
No known key found for this signature in database
GPG Key ID: FCF0DCB4ADFC53E7

View File

@ -49,6 +49,8 @@ def get_sentinel_url_from_env(redis_url, sentinel_hosts_env, sentinel_port_env):
redis_config = parse_redis_service_url(redis_url)
username = redis_config["username"] or ""
password = redis_config["password"] or ""
auth_part = f"{username}:{password}"
auth_part = ""
if username or password:
auth_part = f"{username}:{password}@"
hosts_part = ",".join(f"{host}:{sentinel_port_env}" for host in sentinel_hosts_env.split(","))
return f"redis+sentinel://{auth_part}@{hosts_part}/{redis_config['db']}/{redis_config['service']}"
return f"redis+sentinel://{auth_part}{hosts_part}/{redis_config['db']}/{redis_config['service']}"