feat: capture Redis RPUSH length and log HSET result for suggestions
Changed the Redis RPUSH command to return the new list length (`Result<i64, RedisError>`) and added a debug log that includes this length. Updated the HSET command to capture its result (`Result<i64, RedisError>`), 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.
This commit is contained in:
parent
4337bd4229
commit
8af46bbb06
1 changed files with 14 additions and 11 deletions
|
|
@ -29,29 +29,32 @@ pub fn add_suggestion_keyword(state: Arc<AppState>, user: UserSession, engine: &
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Append suggestion to Redis list
|
// Append suggestion to Redis list - RPUSH returns the new length as i64
|
||||||
let result: Result<(), redis::RedisError> = redis::cmd("RPUSH")
|
let result: Result<i64, redis::RedisError> = redis::cmd("RPUSH")
|
||||||
.arg(&redis_key)
|
.arg(&redis_key)
|
||||||
.arg(suggestion.to_string())
|
.arg(suggestion.to_string())
|
||||||
.query_async(&mut conn)
|
.query_async(&mut conn)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(_) => {
|
Ok(length) => {
|
||||||
debug!("Suggestion added successfully to Redis key {}", redis_key);
|
debug!("Suggestion added successfully to Redis key {}, new length: {}", redis_key, length);
|
||||||
|
|
||||||
// Also register context as inactive initially
|
// Also register context as inactive initially
|
||||||
let active_key = format!("active_context:{}:{}", user.user_id, user.id);
|
let active_key = format!("active_context:{}:{}", user.user_id, user.id);
|
||||||
let _: Result<(), redis::RedisError> = redis::cmd("HSET")
|
let hset_result: Result<i64, redis::RedisError> = redis::cmd("HSET")
|
||||||
.arg(&active_key)
|
.arg(&active_key)
|
||||||
.arg(&context_name)
|
.arg(&context_name)
|
||||||
.arg("inactive")
|
.arg("inactive")
|
||||||
.query_async(&mut conn)
|
.query_async(&mut conn)
|
||||||
.await
|
.await;
|
||||||
.unwrap_or_else(|e| {
|
|
||||||
error!("Failed to set context state: {}", e);
|
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),
|
Err(e) => error!("Failed to add suggestion to Redis: {}", e),
|
||||||
}
|
}
|
||||||
|
|
@ -63,4 +66,4 @@ pub fn add_suggestion_keyword(state: Arc<AppState>, user: UserSession, engine: &
|
||||||
Ok(Dynamic::UNIT)
|
Ok(Dynamic::UNIT)
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
Loading…
Add table
Reference in a new issue