gitdataai/libs/config/redis.rs
ZhenYi beae9bdea0 feat(observability): Phase 6 OTLP tracing for gRPC + config helper
- libs/rpc: slog → tracing; 8 gRPC methods instrumented with
  info_span + Instrument for W3C trace propagation
- libs/session_manager: slog → tracing dependency
- libs/config: add redis_url() singleton helper for adminrpc
2026-04-21 23:05:37 +08:00

43 lines
1.4 KiB
Rust

use crate::AppConfig;
impl AppConfig {
/// Returns a single Redis URL (first from APP_REDIS_URLS or APP_REDIS_URL).
pub fn redis_url(&self) -> anyhow::Result<String> {
let urls = self.redis_urls()?;
urls.into_iter().next().ok_or_else(|| {
anyhow::anyhow!("APP_REDIS_URLS or APP_REDIS_URL is empty")
})
}
pub fn redis_urls(&self) -> anyhow::Result<Vec<String>> {
if let Some(urls) = self.env.get("APP_REDIS_URLS") {
return Ok(urls.split(',').map(|s| s.trim().to_string()).collect());
}
if let Some(url) = self.env.get("APP_REDIS_URL") {
return Ok(vec![url.to_string()]);
}
Err(anyhow::anyhow!("APP_REDIS_URLS or APP_REDIS_URL not found"))
}
pub fn redis_pool_size(&self) -> anyhow::Result<u32> {
if let Some(pool_size) = self.env.get("APP_REDIS_POOL_SIZE") {
return Ok(pool_size.parse::<u32>()?);
}
Ok(10)
}
pub fn redis_connect_timeout(&self) -> anyhow::Result<u64> {
if let Some(timeout) = self.env.get("APP_REDIS_CONNECT_TIMEOUT") {
return Ok(timeout.parse::<u64>()?);
}
Ok(5)
}
pub fn redis_acquire_timeout(&self) -> anyhow::Result<u64> {
if let Some(timeout) = self.env.get("APP_REDIS_ACQUIRE_TIMEOUT") {
return Ok(timeout.parse::<u64>()?);
}
Ok(5)
}
}