diff --git a/crates/redis_interface/src/commands.rs b/crates/redis_interface/src/commands.rs index c283ee575a..1547158e6e 100644 --- a/crates/redis_interface/src/commands.rs +++ b/crates/redis_interface/src/commands.rs @@ -290,6 +290,46 @@ impl super::RedisConnectionPool { .await } + #[instrument(level = "DEBUG", skip(self))] + pub async fn get_multiple_keys( + &self, + keys: K, + ) -> CustomResult>, errors::RedisError> + where + V: FromRedis + Unpin + Send + 'static, + K: Into + 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( + &self, + keys: K, + type_name: &'static str, + ) -> CustomResult>, errors::RedisError> + where + K: Into + Send + Debug, + V: serde::de::DeserializeOwned, + { + let data = self.get_multiple_keys::>(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))] pub async fn serialize_and_set_multiple_hash_field_if_not_exist( &self,