This commit is contained in:
2026-04-09 14:55:37 +02:00
parent 8be455ba98
commit 4a85efc270
30 changed files with 4895 additions and 1 deletions
+29
View File
@@ -0,0 +1,29 @@
use std::time::Duration;
use anyhow::Context;
use redis::Client as RedisClient;
use sqlx::{postgres::PgPoolOptions, PgPool};
pub async fn connect_postgres(database_url: Option<&str>) -> anyhow::Result<Option<PgPool>> {
match database_url {
Some(url) if !url.trim().is_empty() => {
let pool = PgPoolOptions::new()
.max_connections(5)
.acquire_timeout(Duration::from_secs(5))
.connect(url)
.await
.with_context(|| format!("failed to connect to postgres at {url}"))?;
Ok(Some(pool))
}
_ => Ok(None),
}
}
pub fn connect_redis(redis_url: Option<&str>) -> anyhow::Result<Option<RedisClient>> {
match redis_url {
Some(url) if !url.trim().is_empty() => {
Ok(Some(RedisClient::open(url).context("failed to open redis client")?))
}
_ => Ok(None),
}
}