From 9d833919f03690b3f67598800d5b0ec359cb8bbb Mon Sep 17 00:00:00 2001 From: Cesar Rodas Date: Mon, 16 Dec 2024 18:04:46 -0300 Subject: [PATCH] Even more changes Use a more rusty expr instead of match --- crates/cdk-axum/src/cache/backend/redis.rs | 46 +++++++++++++--------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/crates/cdk-axum/src/cache/backend/redis.rs b/crates/cdk-axum/src/cache/backend/redis.rs index baf47356..a6c48891 100644 --- a/crates/cdk-axum/src/cache/backend/redis.rs +++ b/crates/cdk-axum/src/cache/backend/redis.rs @@ -51,40 +51,48 @@ impl HttpCacheStorage for HttpCacheRedis { } async fn get(&self, key: &HttpCacheKey) -> Option> { - let mut conn = match self.client.get_multiplexed_tokio_connection().await { - Ok(conn) => conn, - Err(err) => { + let mut conn = self + .client + .get_multiplexed_tokio_connection() + .await + .map_err(|err| { tracing::error!("Failed to get redis connection: {:?}", err); - return None; - } - }; + err + }) + .ok()?; let mut db_key = self.prefix.clone().unwrap_or_default(); db_key.extend(&**key); - match conn.get(db_key).await { - Ok(result) => result, - Err(err) => { + conn.get(db_key) + .await + .map_err(|err| { tracing::error!("Failed to get value from redis: {:?}", err); - None - } - } + err + }) + .ok()? } async fn set(&self, key: HttpCacheKey, value: Vec) { let mut db_key = self.prefix.clone().unwrap_or_default(); db_key.extend(&*key); - let mut conn = match self.client.get_multiplexed_tokio_connection().await { - Ok(conn) => conn, - Err(err) => { + let mut conn = self + .client + .get_multiplexed_tokio_connection() + .await + .map_err(|err| { tracing::error!("Failed to get redis connection: {:?}", err); - return; - } - }; + err + }) + .ok()?; let _: Result<(), _> = conn .set_ex(db_key, value, self.cache_ttl.as_secs() as usize) - .await; + .await + .map_err(|err| { + tracing::error!("Failed to set value in redis: {:?}", err); + err + }); } }