pub async fn update_dialogue<'a, D>(
        &mut self,
        chat_id: i64,
        from_id: Option<i64>,
        dialogue: D,
    ) -> Result<(), RedisStorageError>
    where
        D: Serialize,
    {
        let key: String = RedisConnection::get_dialogues_key(chat_id);
        let field: String = RedisConnection::get_from_field(from_id);

        // Serialize
        let value: String = serde_json::to_string(&dialogue).map_err(|err| {
            log::info!(
                "{}",
                format_log_chat(&format!("Failed to serialize dialogue: {}", err), chat_id)
            );
            RedisStorageError::SerdeError(err)
        })?;

        // Save
        let set_result: RedisResult<()> = self.connection.hset(&key, &field, &value).await;
        match &set_result {
            Ok(_) => {
                log::info!(
                    "{}",
                    format_log_chat(&format!("Saved dialogue for '{f}'", f = field), chat_id)
                );
            }
            Err(err) => {
                log::info!(
                    "{}",
                    format_log_chat(&format!("Failed to save dialogue to DB: {}", err), chat_id)
                );
            }
        }
        set_result.map_err(RedisStorageError::RedisError)
    }
/// Update a dialogue in the storage.
///
/// Saves the `dialogue` in the redis database for given chat and user.
Update a dialogue in the storage.
Saves the `dialogue` in the redis database for given chat and user.
Update a dialogue in the storage . Saves the ` dialogue ` in the redis database for given chat and user .
pub async fn update_dialogue<'a, D>(
        &mut self,
        chat_id: i64,
        from_id: Option<i64>,
        dialogue: D,
    ) -> Result<(), RedisStorageError>
    where
        D: Serialize,
    {
        let key: String = RedisConnection::get_dialogues_key(chat_id);
        let field: String = RedisConnection::get_from_field(from_id);
        // Serialize
        let value: String = serde_json::to_string(&dialogue).map_err(|err| {
            log::info!(
                "{}",
                format_log_chat(&format!("Failed to serialize dialogue: {}", err), chat_id)
            );
            RedisStorageError::SerdeError(err)
        })?;
        // Save
        let set_result: RedisResult<()> = self.connection.hset(&key, &field, &value).await;
        match &set_result {
            Ok(_) => {
                log::info!(
                    "{}",
                    format_log_chat(&format!("Saved dialogue for '{f}'", f = field), chat_id)
                );
            }
            Err(err) => {
                log::info!(
                    "{}",
                    format_log_chat(&format!("Failed to save dialogue to DB: {}", err), chat_id)
                );
            }
        }
        set_result.map_err(RedisStorageError::RedisError)
    }
pub async fn update_dialogue < ' a , D > ( & mut self , chat_id : i64 , from_id : Option < i64 > , dialogue : D , ) -> Result < ( ) , RedisStorageError > where D : Serialize , { let key : String = RedisConnection :: get_dialogues_key ( chat_id ) ; let field : String = RedisConnection :: get_from_field ( from_id ) ; // Serialize let value : String = serde_json :: to_string ( & dialogue ) . map_err ( | err | { log :: info ! ( " " format_log_chat ( format ( " " err ) chat_id ) ) ; RedisStorageError :: SerdeError ( err ) } ) ? ; // Save let set_result : RedisResult < ( ) > = self . connection . hset ( & key , & field , & value ) . await ; match & set_result { Ok ( _ ) => { log :: info ! ( " " format_log_chat ( format ( " " f field ) chat_id ) ) ; } Err ( err ) => { log :: info ! ( " " format_log_chat ( format ( " " err ) chat_id ) ) ; } } set_result . map_err ( RedisStorageError :: RedisError ) }
Update a dialogue in the storage.
Update a dialogue in the storage .
&mut self
chat_id
i64
from_id
Option<i64>
dialogue
D