fix: init_redis fetches cache password from Vault (fixes connection timeout)
All checks were successful
BotServer CI/CD / build (push) Successful in 4m59s

- Root cause: init_redis() used redis://localhost:6379 without password
- Valkey requires authentication, causing connection timeouts
- Fix: use get_cache_config() from SecretsManager to build URL with password
- Falls back to env vars (CACHE_URL/REDIS_URL/VALKEY_URL) if set
This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2026-04-01 20:17:37 -03:00
parent 3c9e4ba6e7
commit b3edf21d21

View file

@ -284,10 +284,25 @@ pub async fn load_config(
/// Initialize Redis/Valkey cache with retry logic /// Initialize Redis/Valkey cache with retry logic
#[cfg(feature = "cache")] #[cfg(feature = "cache")]
pub async fn init_redis() -> Option<Arc<redis::Client>> { pub async fn init_redis() -> Option<Arc<redis::Client>> {
// Try environment variables first
let cache_url = std::env::var("CACHE_URL") let cache_url = std::env::var("CACHE_URL")
.or_else(|_| std::env::var("REDIS_URL")) .or_else(|_| std::env::var("REDIS_URL"))
.or_else(|_| std::env::var("VALKEY_URL")) .or_else(|_| std::env::var("VALKEY_URL"))
.unwrap_or_else(|_| "redis://localhost:6379".to_string()); .ok();
// If no env var, try to get credentials from Vault
let cache_url = if let Some(url) = cache_url {
url
} else if let Some(secrets) = crate::core::shared::utils::get_secrets_manager().await {
let (host, port, password) = secrets.get_cache_config();
if let Some(pass) = password {
format!("redis://:{}@{}:{}", pass, host, port)
} else {
format!("redis://{}:{}", host, port)
}
} else {
"redis://localhost:6379".to_string()
};
info!("Attempting to connect to cache at: {}", cache_url); info!("Attempting to connect to cache at: {}", cache_url);