feat: add GenericNotFoundError error response and set_key_if_not_exists_with_expiry Redis command (#1526)

This commit is contained in:
Prajjwal Kumar
2023-07-03 18:21:23 +05:30
committed by GitHub
parent 1e87f3d673
commit 9a88a32d50
5 changed files with 22 additions and 6 deletions

View File

@ -175,10 +175,11 @@ impl super::RedisConnectionPool {
}
#[instrument(level = "DEBUG", skip(self))]
pub async fn set_key_if_not_exist<V>(
pub async fn set_key_if_not_exists_with_expiry<V>(
&self,
key: &str,
value: V,
seconds: Option<i64>,
) -> CustomResult<SetnxReply, errors::RedisError>
where
V: TryInto<RedisValue> + Debug + Send + Sync,
@ -188,9 +189,11 @@ impl super::RedisConnectionPool {
.set(
key,
value,
Some(Expiration::EX(self.config.default_ttl.into())),
Some(Expiration::EX(
seconds.unwrap_or(self.config.default_ttl.into()),
)),
Some(SetOptions::NX),
false,
true,
)
.await
.into_report()