use crate::{Error, Forum, Keys, Result};
use redis::Connection;
#[derive(Clone)]
pub struct Context {
forum: Forum,
topic: String,
keys: Keys,
}
impl Context {
pub fn new(forum: Forum, topic: &str) -> Self {
Self {
forum,
topic: topic.to_string(),
keys: Keys::with_topic(topic),
}
}
pub fn get_connection(&self) -> Result<Connection> {
self.forum
.redis_client()
.get_connection()
.map_err(Error::Redis)
}
pub fn topic(&self) -> &str {
&self.topic
}
pub fn keys(&self) -> &Keys {
&self.keys
}
pub fn for_topic(&self, topic: &str) -> Self {
Self::new(self.forum.clone(), topic)
}
}