1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
use futures::future::Future; use redis::{r#async::Connection, Client}; use crate::connection_factory::{ConnectionFactory, NewConnection, NewConnectionError}; use crate::error::{InitializationError, InitializationResult}; use crate::pooled_connection::ConnectionFlavour; use crate::Poolable; impl Poolable for Connection {} pub struct RedisRsFactory(Client); impl RedisRsFactory { pub fn new(connect_to: String) -> InitializationResult<Self> { Ok(Self(Client::open(&*connect_to).map_err(|err| { InitializationError::new( format!("Could not create a redis-rs client to {}", connect_to), Some(Box::new(err)), ) })?)) } } impl ConnectionFactory for RedisRsFactory { type Connection = ConnectionFlavour; fn create_connection(&self) -> NewConnection<Self::Connection> { NewConnection::new( self.0 .get_async_connection() .map(ConnectionFlavour::RedisRs) .map_err(NewConnectionError::new), ) } }