Defining the user session
To define our user session, we must import the following:
// nanoservices/user-session-cache/cache-module/src/user_session.rs
use redis_module::{
Context, RedisString, RedisError, RedisResult, RedisValue
};
use chrono::{DateTime, Utc, NaiveDateTime};
With this, our user session struct has the following definition:
// nanoservices/user-session-cache/cache-module/src/user_session.rs
pub struct UserSession {
pub user_id: String,
pub key: String,
pub session_datetime: DateTime<Utc>,
}
Our user session then has the functions associated below:
// nanoservices/user-session-cache/cache-module/src/user_session.rs
impl UserSession {
pub fn from_id(user_id: String)
-> UserSession {
. . .
}
pub fn check_timeout(&mut self, ctx: &Context)
-> RedisResult {
. . .
}
pub fn update_last_interacted(&self, ctx: &Context)
-> RedisResult {
. . .
}
pub fn get_counter(...