1
Fork 0
mirror of https://github.com/Steffo99/distributed-arcade.git synced 2024-11-28 19:14:23 +00:00
distributed-arcade/src/shortcuts/redis.rs

24 lines
708 B
Rust

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)
}
}