feat(redis_interface): implement MGET command (#1206)

This commit is contained in:
ThisIsMani
2023-05-19 11:36:36 +05:30
committed by GitHub
parent 8947e1c9db
commit 93dcd98640

View File

@ -290,6 +290,46 @@ impl super::RedisConnectionPool {
.await .await
} }
#[instrument(level = "DEBUG", skip(self))]
pub async fn get_multiple_keys<K, V>(
&self,
keys: K,
) -> CustomResult<Vec<Option<V>>, errors::RedisError>
where
V: FromRedis + Unpin + Send + 'static,
K: Into<MultipleKeys> + Send + Debug,
{
self.pool
.mget(keys)
.await
.into_report()
.change_context(errors::RedisError::GetFailed)
}
#[instrument(level = "DEBUG", skip(self))]
pub async fn get_and_deserialize_multiple_keys<K, V>(
&self,
keys: K,
type_name: &'static str,
) -> CustomResult<Vec<Option<V>>, errors::RedisError>
where
K: Into<MultipleKeys> + Send + Debug,
V: serde::de::DeserializeOwned,
{
let data = self.get_multiple_keys::<K, Vec<u8>>(keys).await?;
data.into_iter()
.map(|value_bytes| {
value_bytes
.map(|bytes| {
bytes
.parse_struct(type_name)
.change_context(errors::RedisError::JsonSerializationFailed)
})
.transpose()
})
.collect()
}
#[instrument(level = "DEBUG", skip(self))] #[instrument(level = "DEBUG", skip(self))]
pub async fn serialize_and_set_multiple_hash_field_if_not_exist<V>( pub async fn serialize_and_set_multiple_hash_field_if_not_exist<V>(
&self, &self,