Skip to main content

shaperail_runtime/cache/
pool.rs

1use deadpool_redis::{Config, Pool, Runtime};
2use shaperail_core::ShaperailError;
3
4/// Creates a Redis connection pool from the given URL.
5///
6/// The URL should be in the format `redis://host:port/db`.
7pub fn create_redis_pool(redis_url: &str) -> Result<Pool, ShaperailError> {
8    let cfg = Config::from_url(redis_url);
9    cfg.create_pool(Some(Runtime::Tokio1))
10        .map_err(|e| ShaperailError::Internal(format!("Failed to create Redis pool: {e}")))
11}
12
13#[cfg(test)]
14mod tests {
15    use super::*;
16
17    #[test]
18    fn create_pool_invalid_url_returns_error() {
19        // Empty URL should still create a pool (connection fails lazily)
20        // but a completely broken config might error
21        let result = create_redis_pool("redis://localhost:6379");
22        assert!(result.is_ok());
23    }
24}