29 lines
740 B
Rust
29 lines
740 B
Rust
|
use anyhow::Result;
|
||
|
use lazy_static::lazy_static;
|
||
|
use r2d2_redis::{r2d2, redis, RedisConnectionManager};
|
||
|
|
||
|
use crate::config;
|
||
|
|
||
|
pub type RedisPool = r2d2::Pool<RedisConnectionManager>;
|
||
|
pub type ConnectionPool = r2d2::PooledConnection<RedisConnectionManager>;
|
||
|
|
||
|
pub fn establish_connection() -> Result<redis::Connection> {
|
||
|
Ok(redis::Client::open(config::CONFIG.redis_url.as_str())?.get_connection()?)
|
||
|
}
|
||
|
|
||
|
pub fn pool() -> Result<RedisPool> {
|
||
|
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)
|
||
|
}
|
||
|
}
|