redisesh

Crates.ioredisesh
lib.rsredisesh
version0.1.0
sourcesrc
created_at2021-10-29 10:37:59.636284
updated_at2021-10-29 10:37:59.636284
descriptionRedis based session manager
homepagehttps://github.com/cy6erlion/redisesh
repositoryhttps://github.com/cy6erlion/redisesh
max_upload_size
id473896
size11,555
(cy6erlion)

documentation

README

crates.io

                   .___.__                     .__
_______   ____   __| _/|__| ______ ____   _____|  |__
\_  __ \_/ __ \ / __ | |  |/  ___// __ \ /  ___/  |  \ 
 |  | \/\  ___// /_/ | |  |\___ \\  ___/ \___ \|   Y  \
 |__|    \___  >____ | |__/____  >\___  >____  >___|  /
             \/     \/         \/     \/     \/     \/
                Redis based session manager

Sessions are stored with redis hashes. The session key is 128 random bits (16-bytes) which is encoded with base64. Sessions can be configured to expire.

basic

// Establish redis connection
let mut redisesh = Redisesh::new("redis://127.0.0.1/").unwrap();

// Data to be store in session hash map value
let session_data = Some(String::from("{username: John}"));

// Create a new session by inserting the session data in redis.
// Also generates and returns a random Token which is the key of the
// session in the redis hashmap.
let base64_token = redisesh.insert(session_data).unwrap();

expiration

let mut redisesh = Redisesh::new("redis://127.0.0.1/").unwrap();
let session_data = Some(String::from("{username: John}"));

// Session Expiration date (seconds)
let expiration = std::time::Duration::from_secs(10);

// Set session expiration
redisesh.configure(Config {
  expiration: Some(expiration),
});

// This session expires after 10 seconds
let base64_token = redisesh.insert(session_data).unwrap();

// Sleep for 2 seconds to make sure the session has expired
std::thread::sleep(std::time::Duration::from_secs(2));

// Check if session exists
let exists = redisesh.is_active(&base64_token).unwrap();

// Session does not exist
assert_eq!(exists, false);

Commit count: 12

cargo fmt