async-fred-session

Crates.ioasync-fred-session
lib.rsasync-fred-session
version0.1.5
sourcesrc
created_at2023-01-22 01:00:35.035511
updated_at2023-07-14 21:08:17.884009
descriptionredis session store for async-session backed by fred.rs
homepage
repositoryhttps://github.com/brkp/async-fred-session
max_upload_size
id764679
size15,460
(brkp)

documentation

README

async-fred-session

License: MIT docs.rs crates.io

Redis backed session store for async-session using fred.rs.

use async_fred_session::{RedisSessionStore, fred::{pool::RedisPool, types::RedisConfig}};
use async_session::{Session, SessionStore};

// pool creation
let config = RedisConfig::from_url("redis://127.0.0.1:6379").unwrap();
let rds_pool = RedisPool::new(config, None, None, 6).unwrap();
rds_pool.connect();
rds_pool.wait_for_connect().await.unwrap();

// store and session
let store = RedisSessionStore::from_pool(rds_pool, Some("async-fred-session/".into()));
let mut session = Session::new();
session.insert("key", "value").unwrap();

let cookie_value = store.store_session(session).await.unwrap().unwrap();
let session = store.load_session(cookie_value).await.unwrap().unwrap();
assert_eq!(&session.get::<String>("key").unwrap(), "value");
Commit count: 23

cargo fmt