Skip to content

Commit

Permalink
Even more changes
Browse files Browse the repository at this point in the history
Use a more rusty expr instead of match
  • Loading branch information
crodas committed Dec 16, 2024
1 parent a26bb7a commit 9d83391
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions crates/cdk-axum/src/cache/backend/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,40 +51,48 @@ impl HttpCacheStorage for HttpCacheRedis {
}

async fn get(&self, key: &HttpCacheKey) -> Option<Vec<u8>> {
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<u8>) {
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
});
}
}

0 comments on commit 9d83391

Please sign in to comment.