3535//! .expire(key, 60).ignore()
3636//! .query(&mut connection).unwrap();
3737//! ```
38- use std:: cell:: RefCell ;
39- use std:: collections:: HashSet ;
40- use std:: str:: FromStr ;
41- use std:: thread;
42- use std:: time:: Duration ;
43-
44- use rand:: { seq:: IteratorRandom , thread_rng} ;
45-
4638pub use crate :: cluster_client:: { ClusterClient , ClusterClientBuilder } ;
4739use crate :: cluster_pipeline:: UNROUTABLE_ERROR ;
4840pub use crate :: cluster_pipeline:: { cluster_pipe, ClusterPipeline } ;
@@ -63,6 +55,13 @@ use crate::{
6355 cluster_routing:: { Redirect , Route , RoutingInfo } ,
6456 IntoConnectionInfo , PushInfo ,
6557} ;
58+ use rand:: { seq:: IteratorRandom , thread_rng} ;
59+ use std:: cell:: RefCell ;
60+ use std:: collections:: HashSet ;
61+ use std:: str:: FromStr ;
62+ use std:: sync:: Arc ;
63+ use std:: thread;
64+ use std:: time:: Duration ;
6665
6766use tokio:: sync:: mpsc;
6867
@@ -342,22 +341,20 @@ where
342341 let mut slots = self . slots . borrow_mut ( ) ;
343342 * slots = self . create_new_slots ( ) ?;
344343
345- let mut nodes = slots. values ( ) . flatten ( ) . collect :: < Vec < _ > > ( ) ;
346- nodes. sort_unstable ( ) ;
347- nodes. dedup ( ) ;
348-
344+ let nodes = slots. all_node_addresses ( ) ;
349345 let mut connections = self . connections . borrow_mut ( ) ;
350346 * connections = nodes
351347 . into_iter ( )
352348 . filter_map ( |addr| {
353- if connections. contains_key ( addr) {
354- let mut conn = connections. remove ( addr) . unwrap ( ) ;
349+ let addr = addr. to_string ( ) ;
350+ if connections. contains_key ( & addr) {
351+ let mut conn = connections. remove ( & addr) . unwrap ( ) ;
355352 if conn. check_connection ( ) {
356353 return Some ( ( addr. to_string ( ) , conn) ) ;
357354 }
358355 }
359356
360- if let Ok ( mut conn) = self . connect ( addr) {
357+ if let Ok ( mut conn) = self . connect ( & addr) {
361358 if conn. check_connection ( ) {
362359 return Some ( ( addr. to_string ( ) , conn) ) ;
363360 }
@@ -423,7 +420,7 @@ where
423420 if let Some ( addr) = slots. slot_addr_for_route ( route) {
424421 Ok ( (
425422 addr. to_string ( ) ,
426- self . get_connection_by_addr ( connections, addr) ?,
423+ self . get_connection_by_addr ( connections, & addr) ?,
427424 ) )
428425 } else {
429426 // try a random node next. This is safe if slots are involved
@@ -491,13 +488,13 @@ where
491488 fn execute_on_all < ' a > (
492489 & ' a self ,
493490 input : Input ,
494- addresses : HashSet < & ' a str > ,
491+ addresses : HashSet < Arc < String > > ,
495492 connections : & ' a mut HashMap < String , C > ,
496- ) -> Vec < RedisResult < ( & ' a str , Value ) > > {
493+ ) -> Vec < RedisResult < ( Arc < String > , Value ) > > {
497494 addresses
498495 . into_iter ( )
499496 . map ( |addr| {
500- let connection = self . get_connection_by_addr ( connections, addr) ?;
497+ let connection = self . get_connection_by_addr ( connections, & addr) ?;
501498 match input {
502499 Input :: Slice { cmd, routable : _ } => connection. req_packed_command ( cmd) ,
503500 Input :: Cmd ( cmd) => connection. req_command ( cmd) ,
@@ -522,16 +519,16 @@ where
522519 input : Input ,
523520 slots : & ' a mut SlotMap ,
524521 connections : & ' a mut HashMap < String , C > ,
525- ) -> Vec < RedisResult < ( & ' a str , Value ) > > {
526- self . execute_on_all ( input, slots. addresses_for_all_nodes ( ) , connections)
522+ ) -> Vec < RedisResult < ( Arc < String > , Value ) > > {
523+ self . execute_on_all ( input, slots. all_node_addresses ( ) , connections)
527524 }
528525
529526 fn execute_on_all_primaries < ' a > (
530527 & ' a self ,
531528 input : Input ,
532529 slots : & ' a mut SlotMap ,
533530 connections : & ' a mut HashMap < String , C > ,
534- ) -> Vec < RedisResult < ( & ' a str , Value ) > > {
531+ ) -> Vec < RedisResult < ( Arc < String > , Value ) > > {
535532 self . execute_on_all ( input, slots. addresses_for_all_primaries ( ) , connections)
536533 }
537534
@@ -541,7 +538,7 @@ where
541538 slots : & ' a mut SlotMap ,
542539 connections : & ' a mut HashMap < String , C > ,
543540 routes : & ' b [ ( Route , Vec < usize > ) ] ,
544- ) -> Vec < RedisResult < ( & ' a str , Value ) > >
541+ ) -> Vec < RedisResult < ( Arc < String > , Value ) > >
545542 where
546543 ' b : ' a ,
547544 {
@@ -553,7 +550,7 @@ where
553550 ErrorKind :: IoError ,
554551 "Couldn't find connection" ,
555552 ) ) ) ?;
556- let connection = self . get_connection_by_addr ( connections, addr) ?;
553+ let connection = self . get_connection_by_addr ( connections, & addr) ?;
557554 let ( _, indices) = routes. get ( index) . unwrap ( ) ;
558555 let cmd =
559556 crate :: cluster_routing:: command_for_multi_slot_indices ( & input, indices. iter ( ) ) ;
0 commit comments