Skip to content

Commit

Permalink
cluster_client: use nodes.first() instead of nodes.is_empty()
Browse files Browse the repository at this point in the history
  • Loading branch information
utkarshgupta137 committed Aug 30, 2022
1 parent 0ce6a61 commit 1d04be5
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions redis/src/cluster_client.rs
Expand Up @@ -41,22 +41,26 @@ impl ClusterClientBuilder {
/// usernames, an error is returned.
pub fn build(self) -> RedisResult<ClusterClient> {
let mut initial_nodes = self.initial_nodes?;
if initial_nodes.is_empty() {
return Err(RedisError::from((
ErrorKind::InvalidClientConfig,
"Initial nodes can't be empty.",
)));
}

let first_node = match initial_nodes.first() {
Some(node) => node,
None => {
return Err(RedisError::from((
ErrorKind::InvalidClientConfig,
"Initial nodes can't be empty.",
)))
}
};

let mut cluster_params = self.cluster_params;
let password = if cluster_params.password.is_none() {
cluster_params.password = initial_nodes[0].redis.password.clone();
cluster_params.password = first_node.redis.password.clone();
&cluster_params.password
} else {
&None
};
let username = if cluster_params.username.is_none() {
cluster_params.username = initial_nodes[0].redis.username.clone();
cluster_params.username = first_node.redis.username.clone();
&cluster_params.username
} else {
&None
Expand Down

0 comments on commit 1d04be5

Please sign in to comment.