From 2251eb190b365bedafb335ec5d15c0de952dd1bc Mon Sep 17 00:00:00 2001 From: Pavan Kumar Sunkara Date: Wed, 11 Mar 2020 09:01:53 +0100 Subject: [PATCH] Use connection info for connection manager --- README.md | 2 +- redis/src/lib.rs | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index acb6c1c..a4ff5a2 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ A (possibly not exhaustive) list of adaptors for different backends: Backend | Adaptor Crate ------- | ------------- [tokio-postgres](https://github.com/sfackler/rust-postgres) | [bb8-postgres](https://crates.io/crates/bb8-postgres) -[redis (git master)](https://github.com/mitsuhiko/redis-rs) | [bb8-redis](https://crates.io/crates/bb8-redis) +[redis](https://github.com/mitsuhiko/redis-rs) | [bb8-redis](https://crates.io/crates/bb8-redis) diff --git a/redis/src/lib.rs b/redis/src/lib.rs index 2f373e1..031651e 100644 --- a/redis/src/lib.rs +++ b/redis/src/lib.rs @@ -8,7 +8,7 @@ use futures::future::{Future, FutureExt}; use async_trait::async_trait; use redis::aio::Connection; -use redis::{Client, RedisError}; +use redis::{Client, IntoConnectionInfo, RedisError}; /// `RedisPool` is a convenience wrapper around `bb8::Pool` that hides the fact that /// `RedisConnectionManager` uses an `Option` to smooth over the API incompatibility. @@ -56,8 +56,10 @@ pub struct RedisConnectionManager { impl RedisConnectionManager { /// Create a new `RedisConnectionManager`. - pub fn new(client: Client) -> Result { - Ok(RedisConnectionManager { client }) + pub fn new(info: T) -> Result { + Ok(RedisConnectionManager { + client: Client::open(info.into_connection_info()?)?, + }) } } @@ -67,10 +69,8 @@ impl bb8::ManageConnection for RedisConnectionManager { type Error = RedisError; async fn connect(&self) -> Result { - match self.client.get_async_connection().await { - Ok(conn) => Ok(Some(conn)), - Err(e) => Err(e), - } + let conn = self.client.get_async_connection().await?; + Ok(Some(conn)) } async fn is_valid(&self, mut conn: Self::Connection) -> Result {