fn refresh_slots(&self) -> RedisResult<()> {
        let mut slots = self.slots.borrow_mut();
        *slots = if self.readonly {
            let mut rng = thread_rng();
            self.create_new_slots(|slot_data| {
                let replicas = slot_data.replicas();
                if replicas.is_empty() {
                    slot_data.master().to_string()
                } else {
                    replicas.choose(&mut rng).unwrap().to_string()
                }
            })?
        } else {
            self.create_new_slots(|slot_data| slot_data.master().to_string())?
        };

        let mut connections = self.connections.borrow_mut();
        *connections = {
            // Remove dead connections and connect to new nodes if necessary
            let mut new_connections = HashMap::with_capacity(connections.len());

            for addr in slots.values() {
                if !new_connections.contains_key(addr) {
                    if connections.contains_key(addr) {
                        let mut conn = connections.remove(addr).unwrap();
                        if conn.check_connection() {
                            new_connections.insert(addr.to_string(), conn);
                            continue;
                        }
                    }

                    if let Ok(mut conn) =
                        connect(addr.as_ref(), self.readonly, self.password.clone())
                    {
                        if conn.check_connection() {
                            conn.set_read_timeout(*self.read_timeout.borrow())?;
                            conn.set_write_timeout(*self.write_timeout.borrow())?;
                            new_connections.insert(addr.to_string(), conn);
                        }
                    }
                }
            }
            new_connections
        };

        Ok(())
    }
// Query a node to discover slot-> master mappings.
Query a node to discover slot-> master mappings.
Query a node to discover slot - > master mappings .
fn refresh_slots(&self) -> RedisResult<()> {
        let mut slots = self.slots.borrow_mut();
        *slots = if self.readonly {
            let mut rng = thread_rng();
            self.create_new_slots(|slot_data| {
                let replicas = slot_data.replicas();
                if replicas.is_empty() {
                    slot_data.master().to_string()
                } else {
                    replicas.choose(&mut rng).unwrap().to_string()
                }
            })?
        } else {
            self.create_new_slots(|slot_data| slot_data.master().to_string())?
        };
        let mut connections = self.connections.borrow_mut();
        *connections = {
            // Remove dead connections and connect to new nodes if necessary
            let mut new_connections = HashMap::with_capacity(connections.len());
            for addr in slots.values() {
                if !new_connections.contains_key(addr) {
                    if connections.contains_key(addr) {
                        let mut conn = connections.remove(addr).unwrap();
                        if conn.check_connection() {
                            new_connections.insert(addr.to_string(), conn);
                            continue;
                        }
                    }
                    if let Ok(mut conn) =
                        connect(addr.as_ref(), self.readonly, self.password.clone())
                    {
                        if conn.check_connection() {
                            conn.set_read_timeout(*self.read_timeout.borrow())?;
                            conn.set_write_timeout(*self.write_timeout.borrow())?;
                            new_connections.insert(addr.to_string(), conn);
                        }
                    }
                }
            }
            new_connections
        };
        Ok(())
    }
fn refresh_slots ( & self ) -> RedisResult < ( ) > { let mut slots = self . slots . borrow_mut ( ) ; * slots = if self . readonly { let mut rng = thread_rng ( ) ; self . create_new_slots ( | slot_data | { let replicas = slot_data . replicas ( ) ; if replicas . is_empty ( ) { slot_data . master ( ) . to_string ( ) } else { replicas . choose ( & mut rng ) . unwrap ( ) . to_string ( ) } } ) ? } else { self . create_new_slots ( | slot_data | slot_data . master ( ) . to_string ( ) ) ? } ; let mut connections = self . connections . borrow_mut ( ) ; * connections = { // Remove dead connections and connect to new nodes if necessary let mut new_connections = HashMap :: with_capacity ( connections . len ( ) ) ; for addr in slots . values ( ) { if ! new_connections . contains_key ( addr ) { if connections . contains_key ( addr ) { let mut conn = connections . remove ( addr ) . unwrap ( ) ; if conn . check_connection ( ) { new_connections . insert ( addr . to_string ( ) , conn ) ; continue ; } } if let Ok ( mut conn ) = connect ( addr . as_ref ( ) , self . readonly , self . password . clone ( ) ) { if conn . check_connection ( ) { conn . set_read_timeout ( * self . read_timeout . borrow ( ) ) ? ; conn . set_write_timeout ( * self . write_timeout . borrow ( ) ) ? ; new_connections . insert ( addr . to_string ( ) , conn ) ; } } } } new_connections } ; Ok ( ( ) ) }
Query a node to discover slot-> master mappings.
Query a node to discover slot - > master mappings .
&self
&self