diff --git a/redis/CHANGELOG.md b/redis/CHANGELOG.md index 6ac9232..5bf12c2 100644 --- a/redis/CHANGELOG.md +++ b/redis/CHANGELOG.md @@ -1,9 +1,10 @@ # Change Log -## v0.14.0 +## unreleased * Merge `deadpool-redis-cluster` into `deadpool-redis`. * Remove `redis_cluster_async` dependency in favor of `redis::cluster` / `redis::cluster_async`. +- Update `redis` dependency to version `0.23` ## v0.13.0 diff --git a/redis/src/cluster/config.rs b/redis/src/cluster/config.rs index 9946c64..0af9d37 100644 --- a/redis/src/cluster/config.rs +++ b/redis/src/cluster/config.rs @@ -1,10 +1,7 @@ -use std::{fmt, path::PathBuf}; +pub use crate::config::ConfigError; +use crate::ConnectionInfo; -use redis::RedisError; -#[cfg(feature = "serde")] -use serde_1::{Deserialize, Serialize}; - -use super::{CreatePoolError, Pool, PoolBuilder, PoolConfig, RedisResult, Runtime}; +use super::{CreatePoolError, Pool, PoolBuilder, PoolConfig, Runtime}; /// Configuration object. /// @@ -117,183 +114,3 @@ impl Default for Config { } } } - -/// This is a 1:1 copy of the [`redis::ConnectionAddr`] enumeration. -/// This is duplicated here in order to add support for the -/// [`serde::Deserialize`] trait which is required for the [`serde`] support. -#[derive(Clone, Debug)] -#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] -#[cfg_attr(feature = "serde", serde(crate = "serde_1"))] -pub enum ConnectionAddr { - /// Format for this is `(host, port)`. - Tcp(String, u16), - - /// Format for this is `(host, port)`. - TcpTls { - /// Hostname. - host: String, - - /// Port. - port: u16, - - /// Disable hostname verification when connecting. - /// - /// # Warning - /// - /// You should think very carefully before you use this method. If - /// hostname verification is not used, any valid certificate for any - /// site will be trusted for use from any other. This introduces a - /// significant vulnerability to man-in-the-middle attacks. - insecure: bool, - }, - - /// Format for this is the path to the unix socket. - Unix(PathBuf), -} - -impl Default for ConnectionAddr { - fn default() -> Self { - Self::Tcp("127.0.0.1".to_string(), 6379) - } -} - -impl From for redis::ConnectionAddr { - fn from(addr: ConnectionAddr) -> Self { - match addr { - ConnectionAddr::Tcp(host, port) => Self::Tcp(host, port), - ConnectionAddr::TcpTls { - host, - port, - insecure, - } => Self::TcpTls { - host, - port, - insecure, - }, - ConnectionAddr::Unix(path) => Self::Unix(path), - } - } -} - -impl From for ConnectionAddr { - fn from(addr: redis::ConnectionAddr) -> Self { - match addr { - redis::ConnectionAddr::Tcp(host, port) => Self::Tcp(host, port), - redis::ConnectionAddr::TcpTls { - host, - port, - insecure, - } => ConnectionAddr::TcpTls { - host, - port, - insecure, - }, - redis::ConnectionAddr::Unix(path) => Self::Unix(path), - } - } -} - -/// This is a 1:1 copy of the [`redis::ConnectionInfo`] struct. -/// This is duplicated here in order to add support for the -/// [`serde::Deserialize`] trait which is required for the [`serde`] support. -#[derive(Clone, Debug, Default)] -#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] -#[cfg_attr(feature = "serde", serde(crate = "serde_1"))] -pub struct ConnectionInfo { - /// A connection address for where to connect to. - pub addr: ConnectionAddr, - - /// A boxed connection address for where to connect to. - #[cfg_attr(feature = "serde", serde(flatten))] - pub redis: RedisConnectionInfo, -} - -impl From for redis::ConnectionInfo { - fn from(info: ConnectionInfo) -> Self { - Self { - addr: info.addr.into(), - redis: info.redis.into(), - } - } -} - -impl From for ConnectionInfo { - fn from(info: redis::ConnectionInfo) -> Self { - Self { - addr: info.addr.into(), - redis: info.redis.into(), - } - } -} - -impl redis::IntoConnectionInfo for ConnectionInfo { - fn into_connection_info(self) -> RedisResult { - Ok(self.into()) - } -} - -/// This is a 1:1 copy of the [`redis::RedisConnectionInfo`] struct. -/// This is duplicated here in order to add support for the -/// [`serde::Deserialize`] trait which is required for the [`serde`] support. -#[derive(Clone, Debug, Default)] -#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] -#[cfg_attr(feature = "serde", serde(crate = "serde_1"))] -pub struct RedisConnectionInfo { - /// The database number to use. This is usually `0`. - pub db: i64, - - /// Optionally a username that should be used for connection. - pub username: Option, - - /// Optionally a password that should be used for connection. - pub password: Option, -} - -impl From for redis::RedisConnectionInfo { - fn from(info: RedisConnectionInfo) -> Self { - Self { - db: info.db, - username: info.username, - password: info.password, - } - } -} - -impl From for RedisConnectionInfo { - fn from(info: redis::RedisConnectionInfo) -> Self { - Self { - db: info.db, - username: info.username, - password: info.password, - } - } -} - -/// This error is returned if the configuration contains an error -#[derive(Debug)] -pub enum ConfigError { - /// Both url and connection were specified in the config - UrlAndConnectionSpecified, - /// The [`redis`] crate returned an error when parsing the config - Redis(RedisError), -} - -impl From for ConfigError { - fn from(e: RedisError) -> Self { - Self::Redis(e) - } -} - -impl fmt::Display for ConfigError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::UrlAndConnectionSpecified => write!( - f, - "url and connection must not be specified at the same time." - ), - Self::Redis(e) => write!(f, "Redis: {}", e), - } - } -} - -impl std::error::Error for ConfigError {} diff --git a/redis/src/cluster/mod.rs b/redis/src/cluster/mod.rs index b28a392..a2b9ac7 100644 --- a/redis/src/cluster/mod.rs +++ b/redis/src/cluster/mod.rs @@ -1,25 +1,4 @@ -#![cfg_attr(docsrs, feature(doc_cfg))] -#![deny( - nonstandard_style, - rust_2018_idioms, - rustdoc::broken_intra_doc_links, - rustdoc::private_intra_doc_links -)] -#![forbid(non_ascii_idents, unsafe_code)] -#![warn( - deprecated_in_future, - missing_copy_implementations, - missing_debug_implementations, - missing_docs, - unreachable_pub, - unused_import_braces, - unused_labels, - unused_lifetimes, - unused_qualifications, - unused_results -)] -#![allow(clippy::uninlined_format_args)] - +//! This module extends the library to support Redis Cluster. mod config; use std::{ diff --git a/redis/tests/redis_cluster.rs b/redis/tests/redis_cluster.rs index cd6b849..9febdfd 100644 --- a/redis/tests/redis_cluster.rs +++ b/redis/tests/redis_cluster.rs @@ -37,7 +37,7 @@ fn create_pool() -> deadpool_redis::cluster::Pool { #[tokio::test] async fn test_pipeline() { - use deadpool_redis::cluster::redis::pipe; + use deadpool_redis::redis::pipe; let pool = create_pool(); let mut conn = pool.get().await.unwrap(); let (value,): (String,) = pipe()