Building the update process
For our update process, we have the following outline:
// nanoservices/user-session-cache/cache-module/src/
// processes/update.rs
use redis_module::{
Context, NextArg, RedisError, RedisResult,
RedisString, RedisValue
};
use crate::user_session::UserSession;
pub fn update(ctx: &Context, args: Vec<RedisString>)
-> RedisResult {
. . .
}
Inside our update function, we process the arguments with the code below:
// nanoservices/user-session-cache/cache-module/src/
// processes/update.rs
if args.len() < 2 {
return Err(RedisError::WrongArity);
}
let mut args = args.into_iter().skip(1);
let user_id = args.next_arg()?.to_string();
We then define the use session with the following code:
// nanoservices/user-session-cache/cache-module/src/
// processes/update.rs
let mut user_session = UserSession::from_id(user_id);
let key_string = RedisString::create(None, user_session.key.clone());
let key = ctx.open_key_writable(&key_string...