- 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:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user