Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1/5] cluster: implement proper builder pattern & minor refactor #669

Merged
merged 4 commits into from Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 11 additions & 12 deletions redis/src/cluster.rs
Expand Up @@ -12,7 +12,7 @@
//! use redis::cluster::ClusterClient;
//!
//! let nodes = vec!["redis://127.0.0.1:6379/", "redis://127.0.0.1:6378/", "redis://127.0.0.1:6377/"];
//! let client = ClusterClient::open(nodes).unwrap();
//! let client = ClusterClient::new(nodes).unwrap();
//! let mut connection = client.get_connection().unwrap();
//!
//! let _: () = connection.set("test", "test_data").unwrap();
Expand All @@ -27,7 +27,7 @@
//! use redis::cluster::{cluster_pipe, ClusterClient};
//!
//! let nodes = vec!["redis://127.0.0.1:6379/", "redis://127.0.0.1:6378/", "redis://127.0.0.1:6377/"];
//! let client = ClusterClient::open(nodes).unwrap();
//! let client = ClusterClient::new(nodes).unwrap();
//! let mut connection = client.get_connection().unwrap();
//!
//! let key = "test";
Expand Down Expand Up @@ -55,6 +55,7 @@ use super::{
Cmd, Connection, ConnectionAddr, ConnectionInfo, ConnectionLike, ErrorKind, IntoConnectionInfo,
RedisError, RedisResult, Value,
};
use crate::cluster_client::ClusterParams;

pub use crate::cluster_client::{ClusterClient, ClusterClientBuilder};
use crate::cluster_pipeline::UNROUTABLE_ERROR;
Expand Down Expand Up @@ -95,25 +96,23 @@ impl TlsMode {

impl ClusterConnection {
pub(crate) fn new(
cluster_params: ClusterParams,
utkarshgupta137 marked this conversation as resolved.
Show resolved Hide resolved
initial_nodes: Vec<ConnectionInfo>,
read_from_replicas: bool,
username: Option<String>,
password: Option<String>,
) -> RedisResult<ClusterConnection> {
let connections = Self::create_initial_connections(
&initial_nodes,
read_from_replicas,
username.clone(),
password.clone(),
cluster_params.read_from_replicas,
cluster_params.username.clone(),
cluster_params.password.clone(),
)?;

let connection = ClusterConnection {
connections: RefCell::new(connections),
slots: RefCell::new(SlotMap::new()),
auto_reconnect: RefCell::new(true),
read_from_replicas,
username,
password,
read_from_replicas: cluster_params.read_from_replicas,
username: cluster_params.username,
password: cluster_params.password,
read_timeout: RefCell::new(None),
write_timeout: RefCell::new(None),
#[cfg(feature = "tls")]
Expand All @@ -135,7 +134,7 @@ impl ClusterConnection {
},
#[cfg(not(feature = "tls"))]
tls: None,
initial_nodes,
initial_nodes: initial_nodes.to_vec(),
};
connection.refresh_slots()?;

Expand Down