use redis::{AsyncCommands, RedisError, aio::MultiplexedConnection};
use crate::cache::CallableCache;
pub struct RedisOps;
impl RedisOps {
pub fn get_connection(cache: &CallableCache) -> MultiplexedConnection {
cache.remote_cache.connection.clone()
}
pub async fn set(con: &mut MultiplexedConnection, key: &str, value: &str) -> Result<(), RedisError> {
con.set(key, value).await
}
pub async fn get(con: &mut MultiplexedConnection, key: &str) -> Result<Option<String>, RedisError> {
con.get(key).await
}
pub async fn set_ex(con: &mut MultiplexedConnection, key: &str, value: &str, seconds: u64) -> Result<(), RedisError> {
con.set_ex(key, value, seconds).await
}
pub async fn del(con: &mut MultiplexedConnection, key: &str) -> Result<(), RedisError> {
con.del(key).await
}
pub async fn sadd(con: &mut MultiplexedConnection, key: &str, member: &str) -> Result<(), RedisError> {
con.sadd(key, member).await
}
pub async fn srem(con: &mut MultiplexedConnection, key: &str, member: &str) -> Result<(), RedisError> {
con.srem(key, member).await
}
pub async fn smembers(con: &mut MultiplexedConnection, key: &str) -> Result<Vec<String>, RedisError> {
con.smembers(key).await
}
pub async fn hset(con: &mut MultiplexedConnection, key: &str, field: &str, value: &str) -> Result<(), RedisError> {
con.hset(key, field, value).await
}
pub async fn hget(con: &mut MultiplexedConnection, key: &str, field: &str) -> Result<Option<String>, RedisError> {
con.hget(key, field).await
}
pub async fn hdel(con: &mut MultiplexedConnection, key: &str, field: &str) -> Result<(), RedisError> {
con.hdel(key, field).await
}
pub async fn publish(con: &mut MultiplexedConnection, channel: &str, message: &str) -> Result<(), RedisError> {
con.publish(channel, message).await
}
}