use anyhow::Result; use lazy_static::lazy_static; use r2d2_redis::{r2d2, redis, RedisConnectionManager}; use crate::config; pub type RedisPool = r2d2::Pool; pub type ConnectionPool = r2d2::PooledConnection; pub fn establish_connection() -> Result { Ok(redis::Client::open(config::CONFIG.redis_url.as_str())?.get_connection()?) } pub fn pool() -> Result { Ok(r2d2::Pool::builder().build(RedisConnectionManager::new( config::CONFIG.redis_url.as_str(), )?)?) } lazy_static! { pub static ref POOL: RedisPool = pool().unwrap(); } pub mod keys { pub fn post_content(id: i32) -> String { format!("post_content:{}", id) } }