- add: redis cache refresh function sets the ttl for a key

- update: session service refresh session function now just updates the ttl of the session instead of calling set
This commit is contained in:
2025-03-09 17:08:56 -04:00
parent 0dc69bcfcf
commit 14c6aa485a
7 changed files with 81 additions and 67 deletions

View File

@@ -25,6 +25,8 @@ pub trait Cache {
) -> Result<Option<T>, redis::RedisError>;
async fn delete(&mut self, key: &str) -> redis::RedisResult<()>;
async fn refresh(&self, key: &str, ttl: i64) -> redis::RedisResult<()>;
}
pub struct RedisCache {
@@ -137,4 +139,15 @@ impl Cache for RedisCache {
})?;
conn.del(key).await
}
async fn refresh(&self, key: &str, ttl: i64) -> redis::RedisResult<()> {
let mut conn = self.pool.get().await.map_err(|err| {
redis::RedisError::from((
redis::ErrorKind::IoError,
"Failed to get Redis connection",
format!("{:?}", err),
))
})?;
conn.expire(key, ttl).await
}
}