Skip to content

Commit

Permalink
redis: remove connection manager for deprecated Connection
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Mar 11, 2024
1 parent 725a282 commit 0ff7df4
Showing 1 changed file with 1 addition and 44 deletions.
45 changes: 1 addition & 44 deletions redis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ pub use bb8;
pub use redis;

use async_trait::async_trait;
use redis::{
aio::{Connection, MultiplexedConnection},
ErrorKind,
};
use redis::{aio::MultiplexedConnection, ErrorKind};
use redis::{Client, IntoConnectionInfo, RedisError};

/// A `bb8::ManageConnection` for `redis::Client::get_async_connection`.
Expand All @@ -63,46 +60,6 @@ impl RedisConnectionManager {

#[async_trait]
impl bb8::ManageConnection for RedisConnectionManager {
type Connection = Connection;
type Error = RedisError;

async fn connect(&self) -> Result<Self::Connection, Self::Error> {
self.client.get_async_connection().await
}

async fn is_valid(&self, conn: &mut Self::Connection) -> Result<(), Self::Error> {
let pong: String = redis::cmd("PING").query_async(conn).await?;
match pong.as_str() {
"PONG" => Ok(()),
_ => Err((ErrorKind::ResponseError, "ping request").into()),
}
}

fn has_broken(&self, _: &mut Self::Connection) -> bool {
false
}
}

/// A `bb8::ManageConnection` for `redis::Client::get_multiplexed_async_connection`.
#[derive(Clone, Debug)]
pub struct RedisMultiplexedConnectionManager {
client: Client,
}

impl RedisMultiplexedConnectionManager {
/// Create a new `RedisMultiplexedConnectionManager`.
/// See `redis::Client::open` for a description of the parameter types.
pub fn new<T: IntoConnectionInfo>(
info: T,
) -> Result<RedisMultiplexedConnectionManager, RedisError> {
Ok(RedisMultiplexedConnectionManager {
client: Client::open(info.into_connection_info()?)?,
})
}
}

#[async_trait]
impl bb8::ManageConnection for RedisMultiplexedConnectionManager {
type Connection = MultiplexedConnection;
type Error = RedisError;

Expand Down

0 comments on commit 0ff7df4

Please sign in to comment.