January 2019
Intermediate to advanced
520 pages
14h 32m
English
Our example needs three functions. The first function, add_session, adds an association between the token and user ID:
fn add_session(conn: &Connection, token: &str, uid: &str) -> Result<(), RedisError> { conn.hset(SESSIONS, token, uid)}
This function only calls the hset method of a Connection and sets the uid value by the token key in the SESSIONS map. It returns RedisError if something is wrong with a set operation.
The next function, remove_session, is also pretty simple and calls the hdel method of Connection:
fn remove_session(conn: &Connection, token: &str) -> Result<(), RedisError> { conn.hdel(SESSIONS, token)}
This function deletes a record with the token key from the SESSIONS map.
The last function,
Read now
Unlock full access