pub(crate) async fn read_from_redis(&mut self, chat_id: ChatId) -> anyhow::Result<()> {
        // check whether we have data for this chat already loaded into memory
        if self.loaded.contains(&chat_id) {
            return Ok(());
        }

        log::info!("preparing to load data for chat id {}", chat_id);

        let mut user_data: HashMap<UserName, String> = HashMap::new();

        match self.redis_con {
            Some(ref mut redis_con) => {
                let key_patt = format!("{}*", i64::from(chat_id));
                let keys: Vec<String> = redis_con.keys(key_patt).await?;

                for key in keys {
                    let (_, name) = key.split_once('_').unwrap();
                    let raw = redis_con.get(&key).await?;
                    user_data.insert(UserName::from(name), raw);
                }
            }
            None => {
                log::warn!("read_from_redis: can't read data for chat, redis client is not ready");
            }
        };

        // deserialize
        for (name, raw) in user_data {
            log::info!("loading data for {}...", name);
            let chains = self.insert_new_chat_id_user(chat_id, &name);
            chains.deserialize(&raw);
        }

        self.loaded.insert(chat_id);
        log::info!("data for chat {} loaded", chat_id);

        Ok(())
    }
/// Reads all data from redis for required chat
Reads all data from redis for required chat
Reads all data from redis for required chat
pub(crate) async fn read_from_redis(&mut self, chat_id: ChatId) -> anyhow::Result<()> {
        // check whether we have data for this chat already loaded into memory
        if self.loaded.contains(&chat_id) {
            return Ok(());
        }
        log::info!("preparing to load data for chat id {}", chat_id);
        let mut user_data: HashMap<UserName, String> = HashMap::new();
        match self.redis_con {
            Some(ref mut redis_con) => {
                let key_patt = format!("{}*", i64::from(chat_id));
                let keys: Vec<String> = redis_con.keys(key_patt).await?;
                for key in keys {
                    let (_, name) = key.split_once('_').unwrap();
                    let raw = redis_con.get(&key).await?;
                    user_data.insert(UserName::from(name), raw);
                }
            }
            None => {
                log::warn!("read_from_redis: can't read data for chat, redis client is not ready");
            }
        };
        // deserialize
        for (name, raw) in user_data {
            log::info!("loading data for {}...", name);
            let chains = self.insert_new_chat_id_user(chat_id, &name);
            chains.deserialize(&raw);
        }
        self.loaded.insert(chat_id);
        log::info!("data for chat {} loaded", chat_id);
        Ok(())
    }
pub ( crate ) async fn read_from_redis ( & mut self , chat_id : ChatId ) -> anyhow :: Result < ( ) > { // check whether we have data for this chat already loaded into memory if self . loaded . contains ( & chat_id ) { return Ok ( ( ) ) ; } log :: info ! ( " " chat_id ) ; let mut user_data : HashMap < UserName , String > = HashMap :: new ( ) ; match self . redis_con { Some ( ref mut redis_con ) => { let key_patt = format ! ( " " i64 from ( chat_id ) ) ; let keys : Vec < String > = redis_con . keys ( key_patt ) . await ? ; for key in keys { let ( _ , name ) = key . split_once ( '_' ) . unwrap ( ) ; let raw = redis_con . get ( & key ) . await ? ; user_data . insert ( UserName :: from ( name ) , raw ) ; } } None => { log :: warn ! ( " " ) ; } } ; // deserialize for ( name , raw ) in user_data { log :: info ! ( " " name ) ; let chains = self . insert_new_chat_id_user ( chat_id , & name ) ; chains . deserialize ( & raw ) ; } self . loaded . insert ( chat_id ) ; log :: info ! ( " " chat_id ) ; Ok ( ( ) ) }
Reads all data from redis for required chat
Reads all data from redis for required chat
&mut self
chat_id
ChatId
&mut self
chat_id
ChatId