30 lines
730 B
Rust
30 lines
730 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 type Connection = redis::Connection;
|
|
|
|
pub fn establish_connection() -> Result<RedisConnectionManager> {
|
|
Ok(RedisConnectionManager::new(
|
|
config::CONFIG.redis_url.as_str(),
|
|
)?)
|
|
}
|
|
|
|
pub fn pool() -> Result<RedisPool> {
|
|
Ok(r2d2::Pool::builder().build(establish_connection()?)?)
|
|
}
|
|
|
|
lazy_static! {
|
|
pub static ref POOL: RedisPool = pool().unwrap();
|
|
}
|
|
|
|
pub mod keys {
|
|
pub const HTML: &str = "html";
|
|
pub const DISPLAY_HTML: &str = "disp_html";
|
|
}
|