@@ -227,7 +227,7 @@ impl ClusterConnection {
227
227
_ => panic ! ( "No reach." ) ,
228
228
} ;
229
229
230
- if let Ok ( mut conn) = connect (
230
+ if let Ok ( mut conn) = Self :: connect (
231
231
info. clone ( ) ,
232
232
read_from_replicas,
233
233
username. clone ( ) ,
@@ -281,7 +281,7 @@ impl ClusterConnection {
281
281
}
282
282
}
283
283
284
- if let Ok ( mut conn) = connect (
284
+ if let Ok ( mut conn) = Self :: connect (
285
285
addr. as_ref ( ) ,
286
286
self . read_from_replicas ,
287
287
self . username . clone ( ) ,
@@ -359,6 +359,28 @@ impl ClusterConnection {
359
359
}
360
360
}
361
361
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
+
362
384
fn get_connection < ' a > (
363
385
& self ,
364
386
connections : & ' a mut HashMap < String , Connection > ,
@@ -388,7 +410,7 @@ impl ClusterConnection {
388
410
} else {
389
411
// Create new connection.
390
412
// TODO: error handling
391
- let conn = connect (
413
+ let conn = Self :: connect (
392
414
addr,
393
415
self . read_from_replicas ,
394
416
self . username . clone ( ) ,
@@ -723,28 +745,6 @@ impl ConnectionLike for ClusterConnection {
723
745
}
724
746
}
725
747
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
-
748
748
fn get_random_connection < ' a > (
749
749
connections : & ' a mut HashMap < String , Connection > ,
750
750
excludes : Option < & ' a HashSet < String > > ,
0 commit comments