use redis::aio::ConnectionLike; use redis::cluster_async::ClusterConnection; use redis::{RedisFuture, Value}; type MultiplexedConnection = redis::aio::MultiplexedConnection; pub enum RedisConn { Single(MultiplexedConnection), Cluster(ClusterConnection), Sentinel(MultiplexedConnection), } impl ConnectionLike for RedisConn { fn req_packed_command<'a>(&'a mut self, cmd: &'a redis::Cmd) -> RedisFuture<'a, Value> { match self { RedisConn::Single(c) | RedisConn::Sentinel(c) => c.req_packed_command(cmd), RedisConn::Cluster(c) => c.req_packed_command(cmd), } } fn req_packed_commands<'a>( &'a mut self, cmd: &'a redis::Pipeline, offset: usize, count: usize, ) -> RedisFuture<'a, Vec> { match self { RedisConn::Single(c) | RedisConn::Sentinel(c) => { c.req_packed_commands(cmd, offset, count) } RedisConn::Cluster(c) => c.req_packed_commands(cmd, offset, count), } } fn get_db(&self) -> i64 { match self { RedisConn::Single(c) | RedisConn::Sentinel(c) => c.get_db(), RedisConn::Cluster(c) => c.get_db(), } } } pub enum RedisConnClone { Single(MultiplexedConnection), Cluster(ClusterConnection), Sentinel(MultiplexedConnection), } impl ConnectionLike for RedisConnClone { fn req_packed_command<'a>(&'a mut self, cmd: &'a redis::Cmd) -> RedisFuture<'a, Value> { match self { RedisConnClone::Single(c) | RedisConnClone::Sentinel(c) => c.req_packed_command(cmd), RedisConnClone::Cluster(c) => c.req_packed_command(cmd), } } fn req_packed_commands<'a>( &'a mut self, cmd: &'a redis::Pipeline, offset: usize, count: usize, ) -> RedisFuture<'a, Vec> { match self { RedisConnClone::Single(c) | RedisConnClone::Sentinel(c) => { c.req_packed_commands(cmd, offset, count) } RedisConnClone::Cluster(c) => c.req_packed_commands(cmd, offset, count), } } fn get_db(&self) -> i64 { match self { RedisConnClone::Single(c) | RedisConnClone::Sentinel(c) => c.get_db(), RedisConnClone::Cluster(c) => c.get_db(), } } }