From 8af46bbb060f0a97cbe80565125e30d8741abf37 Mon Sep 17 00:00:00 2001 From: christopher Date: Fri, 31 Oct 2025 15:58:54 -0300 Subject: [PATCH] feat: capture Redis RPUSH length and log HSET result for suggestions Changed the Redis RPUSH command to return the new list length (`Result`) and added a debug log that includes this length. Updated the HSET command to capture its result (`Result`), logging the number of fields added on success and handling errors explicitly. Removed unnecessary `unwrap_or_else` and added comments to clarify behavior, improving observability and error handling for suggestion storage. --- src/basic/keywords/add_suggestion.rs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/basic/keywords/add_suggestion.rs b/src/basic/keywords/add_suggestion.rs index bc2c177c..6791be98 100644 --- a/src/basic/keywords/add_suggestion.rs +++ b/src/basic/keywords/add_suggestion.rs @@ -29,29 +29,32 @@ pub fn add_suggestion_keyword(state: Arc, user: UserSession, engine: & } }; - // Append suggestion to Redis list - let result: Result<(), redis::RedisError> = redis::cmd("RPUSH") + // Append suggestion to Redis list - RPUSH returns the new length as i64 + let result: Result = redis::cmd("RPUSH") .arg(&redis_key) .arg(suggestion.to_string()) .query_async(&mut conn) .await; match result { - Ok(_) => { - debug!("Suggestion added successfully to Redis key {}", redis_key); + Ok(length) => { + debug!("Suggestion added successfully to Redis key {}, new length: {}", redis_key, length); // Also register context as inactive initially let active_key = format!("active_context:{}:{}", user.user_id, user.id); - let _: Result<(), redis::RedisError> = redis::cmd("HSET") + let hset_result: Result = redis::cmd("HSET") .arg(&active_key) .arg(&context_name) .arg("inactive") .query_async(&mut conn) - .await - .unwrap_or_else(|e| { - error!("Failed to set context state: {}", e); - () - }); + .await; + + match hset_result { + Ok(fields_added) => { + debug!("Context state set to inactive for {}, fields added: {}", context_name, fields_added) + }, + Err(e) => error!("Failed to set context state: {}", e), + } } Err(e) => error!("Failed to add suggestion to Redis: {}", e), } @@ -63,4 +66,4 @@ pub fn add_suggestion_keyword(state: Arc, user: UserSession, engine: & Ok(Dynamic::UNIT) }) .unwrap(); -} +} \ No newline at end of file