1
Fork 0
mirror of https://github.com/Steffo99/distributed-arcade.git synced 2024-11-29 03:24:24 +00:00
distributed-arcade/src/shortcuts/redis.rs

25 lines
708 B
Rust
Raw Normal View History

2022-11-12 01:34:03 +00:00
use async_trait::async_trait;
use axum::http::StatusCode;
use crate::outcome;
#[async_trait]
pub(crate) trait RedisConnectOr504 {
async fn get_connection_or_504(&self) -> Result<redis::aio::Connection, outcome::RequestTuple>;
}
#[async_trait]
impl RedisConnectOr504 for redis::Client {
async fn get_connection_or_504(&self) -> Result<redis::aio::Connection, outcome::RequestTuple> {
log::trace!("Connecting to Redis...");
let rconn = self.get_async_connection().await
.map_err(|_|
(StatusCode::GATEWAY_TIMEOUT, outcome::req_error!("Could not connect to Redis"))
)?;
log::trace!("Connection successful!");
Ok(rconn)
}
}