Skip to content

Commit

Permalink
Connect to Redis each time for ping.
Browse files Browse the repository at this point in the history
  • Loading branch information
emmiegit committed Apr 30, 2024
1 parent 4e3a72e commit 1e20a9a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
7 changes: 3 additions & 4 deletions deepwell/src/endpoints/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@ async fn postgres_check(ctx: &ServiceContext<'_>) -> Result<()> {
}

async fn redis_check(ctx: &ServiceContext<'_>) -> Result<()> {
/*
ctx.redis()
let mut redis = ctx.redis_connect().await?;

redis
.send_packed_command(redis::Cmd::new().arg("PING"))
.await?;

debug!("Successfully pinged Redis");
Ok(())
*/
todo!()
}

pub async fn ping(
Expand Down
14 changes: 12 additions & 2 deletions deepwell/src/services/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ use crate::api::ServerState;
use crate::config::Config;
use crate::locales::Localizations;
use crate::services::blob::MimeAnalyzer;
use redis::aio::ConnectionManager;
use crate::services::error::Result;
use redis::aio::MultiplexedConnection as RedisMultiplexedConnection;
use rsmq_async::PooledRsmq;
use s3::bucket::Bucket;
use sea_orm::DatabaseTransaction;
Expand Down Expand Up @@ -53,10 +54,19 @@ impl<'txn> ServiceContext<'txn> {
}

#[inline]
pub fn redis(&self) -> &redis::Client {
pub fn redis_client(&self) -> &redis::Client {
&self.state.redis
}

pub async fn redis_connect(&self) -> Result<RedisMultiplexedConnection> {
let conn = self
.redis_client()
.get_multiplexed_tokio_connection()
.await?;

Ok(conn)
}

#[inline]
pub fn rsmq(&self) -> PooledRsmq {
PooledRsmq::clone(&self.state.rsmq)
Expand Down

0 comments on commit 1e20a9a

Please sign in to comment.