diff --git a/redis/Cargo.toml b/redis/Cargo.toml index 4ccea78..b7f5517 100644 --- a/redis/Cargo.toml +++ b/redis/Cargo.toml @@ -6,10 +6,15 @@ license = "MIT" repository = "https://github.com/djc/bb8" edition = "2018" +[features] +multiplexed-connections = [] + [dependencies] async-trait = "0.1" bb8 = { version = "0.7", path = "../bb8" } -redis = { version = "0.21.1", default-features = false, features = ["tokio-comp"] } +redis = { version = "0.21.1", default-features = false, features = [ + "tokio-comp", +] } [dev-dependencies] futures-util = "0.3.15" diff --git a/redis/src/lib.rs b/redis/src/lib.rs index 8ac1ba3..2839d29 100644 --- a/redis/src/lib.rs +++ b/redis/src/lib.rs @@ -41,7 +41,11 @@ pub use bb8; pub use redis; use async_trait::async_trait; -use redis::{aio::Connection, ErrorKind}; +#[cfg(not(feature = "multiplexed-connections"))] +use redis::aio::Connection; +#[cfg(feature = "multiplexed-connections")] +use redis::aio::MultiplexedConnection; +use redis::ErrorKind; use redis::{Client, IntoConnectionInfo, RedisError}; /// A `bb8::ManageConnection` for `redis::Client::get_async_connection`. @@ -62,11 +66,19 @@ impl RedisConnectionManager { #[async_trait] impl bb8::ManageConnection for RedisConnectionManager { + #[cfg(not(feature = "multiplexed-connections"))] type Connection = Connection; + #[cfg(feature = "multiplexed-connections")] + type Connection = MultiplexedConnection; + type Error = RedisError; async fn connect(&self) -> Result { - self.client.get_async_connection().await + #[cfg(not(feature = "multiplexed-connections"))] + return self.client.get_async_connection().await; + + #[cfg(feature = "multiplexed-connections")] + self.client.get_multiplexed_async_connection().await } async fn is_valid(