Skip to content

Commit c10919a

Browse files
0xWOFdjc
authored andcommitted
cluster: move connect to main impl
cluster: use modified connect method
1 parent 66fb8ee commit c10919a

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

redis/src/cluster.rs

+25-25
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl ClusterConnection {
227227
_ => panic!("No reach."),
228228
};
229229

230-
if let Ok(mut conn) = connect(
230+
if let Ok(mut conn) = Self::connect(
231231
info.clone(),
232232
read_from_replicas,
233233
username.clone(),
@@ -281,7 +281,7 @@ impl ClusterConnection {
281281
}
282282
}
283283

284-
if let Ok(mut conn) = connect(
284+
if let Ok(mut conn) = Self::connect(
285285
addr.as_ref(),
286286
self.read_from_replicas,
287287
self.username.clone(),
@@ -359,6 +359,28 @@ impl ClusterConnection {
359359
}
360360
}
361361

362+
fn connect<T: IntoConnectionInfo>(
363+
info: T,
364+
read_from_replicas: bool,
365+
username: Option<String>,
366+
password: Option<String>,
367+
) -> RedisResult<Connection>
368+
where
369+
T: std::fmt::Debug,
370+
{
371+
let mut connection_info = info.into_connection_info()?;
372+
connection_info.redis.username = username;
373+
connection_info.redis.password = password;
374+
let client = super::Client::open(connection_info)?;
375+
376+
let mut conn = client.get_connection()?;
377+
if read_from_replicas {
378+
// If READONLY is sent to primary nodes, it will have no effect
379+
cmd("READONLY").query(&mut conn)?;
380+
}
381+
Ok(conn)
382+
}
383+
362384
fn get_connection<'a>(
363385
&self,
364386
connections: &'a mut HashMap<String, Connection>,
@@ -388,7 +410,7 @@ impl ClusterConnection {
388410
} else {
389411
// Create new connection.
390412
// TODO: error handling
391-
let conn = connect(
413+
let conn = Self::connect(
392414
addr,
393415
self.read_from_replicas,
394416
self.username.clone(),
@@ -723,28 +745,6 @@ impl ConnectionLike for ClusterConnection {
723745
}
724746
}
725747

726-
fn connect<T: IntoConnectionInfo>(
727-
info: T,
728-
read_from_replicas: bool,
729-
username: Option<String>,
730-
password: Option<String>,
731-
) -> RedisResult<Connection>
732-
where
733-
T: std::fmt::Debug,
734-
{
735-
let mut connection_info = info.into_connection_info()?;
736-
connection_info.redis.username = username;
737-
connection_info.redis.password = password;
738-
let client = super::Client::open(connection_info)?;
739-
740-
let mut con = client.get_connection()?;
741-
if read_from_replicas {
742-
// If READONLY is sent to primary nodes, it will have no effect
743-
cmd("READONLY").query(&mut con)?;
744-
}
745-
Ok(con)
746-
}
747-
748748
fn get_random_connection<'a>(
749749
connections: &'a mut HashMap<String, Connection>,
750750
excludes: Option<&'a HashSet<String>>,

0 commit comments

Comments
 (0)