use crate::{Error, Result};
use redis::Client as RedisClient;
pub struct Forum {
redis_client: RedisClient,
}
impl Forum {
pub fn new(redis_url: &str) -> Result<Self> {
let redis_client = RedisClient::open(redis_url).map_err(Error::Redis)?;
Ok(Self { redis_client })
}
pub fn default() -> Result<Self> {
let redis_url = crate::util::get_redis_url();
Self::new(&redis_url)
}
pub fn topic(&self, topic: &str) -> crate::Context {
crate::Context::new(self.clone(), topic)
}
pub(crate) fn redis_client(&self) -> &RedisClient {
&self.redis_client
}
}
impl Clone for Forum {
fn clone(&self) -> Self {
Self {
redis_client: self.redis_client.clone(),
}
}
}