1use crate::ConnectionError;
2use crate::client::{RedisClient, RedisConfig};
3use crate::error::Result;
4use redis::aio::ConnectionManager;
5use std::time::Duration;
6
7#[derive(Debug, Clone)]
9pub struct PoolConfig {
10 pub connection_timeout: Duration,
12 pub retry_interval: Duration,
14 pub max_retries: u32,
16 pub keep_alive: bool,
18}
19
20impl Default for PoolConfig {
21 fn default() -> Self {
22 Self {
23 connection_timeout: Duration::from_secs(30),
24 retry_interval: Duration::from_millis(100),
25 max_retries: 3,
26 keep_alive: true,
27 }
28 }
29}
30
31pub struct RedisPool;
33
34impl RedisPool {
35 pub async fn create(config: RedisConfig) -> Result<ConnectionManager> {
46 let redis_url = RedisClient::build_redis_url(&config)?;
48
49 let client = redis::Client::open(redis_url)
51 .map_err(|e| ConnectionError::PoolCreation(format!("Failed to create client: {e}")))?;
52
53 let manager = ConnectionManager::new(client).await.map_err(|e| {
55 ConnectionError::PoolCreation(format!("Failed to create connection manager: {e}"))
56 })?;
57
58 Ok(manager)
59 }
60}