mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 17:19:15 +08:00
feat(kv): add kv wrapper for executing kv tasks (#2384)
This commit is contained in:
@ -232,6 +232,7 @@ impl super::RedisConnectionPool {
|
||||
&self,
|
||||
key: &str,
|
||||
values: V,
|
||||
ttl: Option<u32>,
|
||||
) -> CustomResult<(), errors::RedisError>
|
||||
where
|
||||
V: TryInto<RedisMap> + Debug + Send + Sync,
|
||||
@ -246,7 +247,9 @@ impl super::RedisConnectionPool {
|
||||
|
||||
// setting expiry for the key
|
||||
output
|
||||
.async_and_then(|_| self.set_expiry(key, self.config.default_hash_ttl.into()))
|
||||
.async_and_then(|_| {
|
||||
self.set_expiry(key, ttl.unwrap_or(self.config.default_hash_ttl).into())
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
@ -256,6 +259,7 @@ impl super::RedisConnectionPool {
|
||||
key: &str,
|
||||
field: &str,
|
||||
value: V,
|
||||
ttl: Option<u32>,
|
||||
) -> CustomResult<HsetnxReply, errors::RedisError>
|
||||
where
|
||||
V: TryInto<RedisValue> + Debug + Send + Sync,
|
||||
@ -270,7 +274,7 @@ impl super::RedisConnectionPool {
|
||||
|
||||
output
|
||||
.async_and_then(|inner| async {
|
||||
self.set_expiry(key, self.config.default_hash_ttl.into())
|
||||
self.set_expiry(key, ttl.unwrap_or(self.config.default_hash_ttl).into())
|
||||
.await?;
|
||||
Ok(inner)
|
||||
})
|
||||
@ -283,6 +287,7 @@ impl super::RedisConnectionPool {
|
||||
key: &str,
|
||||
field: &str,
|
||||
value: V,
|
||||
ttl: Option<u32>,
|
||||
) -> CustomResult<HsetnxReply, errors::RedisError>
|
||||
where
|
||||
V: serde::Serialize + Debug,
|
||||
@ -290,7 +295,7 @@ impl super::RedisConnectionPool {
|
||||
let serialized = Encode::<V>::encode_to_vec(&value)
|
||||
.change_context(errors::RedisError::JsonSerializationFailed)?;
|
||||
|
||||
self.set_hash_field_if_not_exist(key, field, serialized.as_slice())
|
||||
self.set_hash_field_if_not_exist(key, field, serialized.as_slice(), ttl)
|
||||
.await
|
||||
}
|
||||
|
||||
@ -339,6 +344,7 @@ impl super::RedisConnectionPool {
|
||||
&self,
|
||||
kv: &[(&str, V)],
|
||||
field: &str,
|
||||
ttl: Option<u32>,
|
||||
) -> CustomResult<Vec<HsetnxReply>, errors::RedisError>
|
||||
where
|
||||
V: serde::Serialize + Debug,
|
||||
@ -346,7 +352,7 @@ impl super::RedisConnectionPool {
|
||||
let mut hsetnx: Vec<HsetnxReply> = Vec::with_capacity(kv.len());
|
||||
for (key, val) in kv {
|
||||
hsetnx.push(
|
||||
self.serialize_and_set_hash_field_if_not_exist(key, field, val)
|
||||
self.serialize_and_set_hash_field_if_not_exist(key, field, val, ttl)
|
||||
.await?,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user