Skip to content

Commit

Permalink
Use connection info for connection manager
Browse files Browse the repository at this point in the history
  • Loading branch information
pksunkara authored and djc committed Mar 12, 2020
1 parent 315f602 commit 2251eb1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)



Expand Down
14 changes: 7 additions & 7 deletions redis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Connection>` to smooth over the API incompatibility.
Expand Down Expand Up @@ -56,8 +56,10 @@ pub struct RedisConnectionManager {

impl RedisConnectionManager {
/// Create a new `RedisConnectionManager`.
pub fn new(client: Client) -> Result<RedisConnectionManager, RedisError> {
Ok(RedisConnectionManager { client })
pub fn new<T: IntoConnectionInfo>(info: T) -> Result<RedisConnectionManager, RedisError> {
Ok(RedisConnectionManager {
client: Client::open(info.into_connection_info()?)?,
})
}
}

Expand All @@ -67,10 +69,8 @@ impl bb8::ManageConnection for RedisConnectionManager {
type Error = RedisError;

async fn connect(&self) -> Result<Self::Connection, Self::Error> {
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<Self::Connection, Self::Error> {
Expand Down

0 comments on commit 2251eb1

Please sign in to comment.