use REDIS_URL if present
This commit is contained in:
parent
f8d2570bb3
commit
39fa1c6e4e
1 changed files with 43 additions and 13 deletions
|
|
@ -56,20 +56,50 @@ if config_env() == :prod do
|
|||
host = System.get_env("PHX_HOST") || "example.com"
|
||||
|
||||
# Configure Redis/Valkey connection
|
||||
redis_host = System.get_env("REDIS_HOST") || "localhost"
|
||||
redis_port = String.to_integer(System.get_env("REDIS_PORT") || "6379")
|
||||
redis_password = System.get_env("REDIS_PASSWORD")
|
||||
|
||||
redis_config = [
|
||||
host: redis_host,
|
||||
port: redis_port
|
||||
]
|
||||
|
||||
# Dokku sets REDIS_URL, K8s uses individual env vars
|
||||
redis_config =
|
||||
if redis_password do
|
||||
Keyword.put(redis_config, :password, redis_password)
|
||||
else
|
||||
redis_config
|
||||
case System.get_env("REDIS_URL") do
|
||||
nil ->
|
||||
# Use individual env vars (K8s pattern)
|
||||
redis_host = System.get_env("REDIS_HOST") || "localhost"
|
||||
redis_port = String.to_integer(System.get_env("REDIS_PORT") || "6379")
|
||||
redis_password = System.get_env("REDIS_PASSWORD")
|
||||
|
||||
base_config = [
|
||||
host: redis_host,
|
||||
port: redis_port
|
||||
]
|
||||
|
||||
if redis_password do
|
||||
Keyword.put(base_config, :password, redis_password)
|
||||
else
|
||||
base_config
|
||||
end
|
||||
|
||||
redis_url ->
|
||||
# Parse REDIS_URL (Dokku pattern)
|
||||
uri = URI.parse(redis_url)
|
||||
|
||||
base_config = [
|
||||
host: uri.host || "localhost",
|
||||
port: uri.port || 6379
|
||||
]
|
||||
|
||||
# Extract password from userinfo if present
|
||||
case uri.userinfo do
|
||||
nil ->
|
||||
base_config
|
||||
|
||||
userinfo ->
|
||||
# userinfo can be "password" or "username:password"
|
||||
password =
|
||||
case String.split(userinfo, ":", parts: 2) do
|
||||
[pass] -> pass
|
||||
[_user, pass] -> pass
|
||||
end
|
||||
|
||||
Keyword.put(base_config, :password, password)
|
||||
end
|
||||
end
|
||||
|
||||
# Configure SSL options based on environment variables
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue