#session #redis #tokio

async-fred-session

redis session store for async-session backed by fred.rs

6 releases

0.1.5 Jul 14, 2023
0.1.4 Apr 18, 2023
0.1.2 Jan 23, 2023

#785 in HTTP server

Download history 98/week @ 2024-03-11 66/week @ 2024-03-18 69/week @ 2024-03-25 104/week @ 2024-04-01 57/week @ 2024-04-08 7/week @ 2024-04-15 15/week @ 2024-04-22 13/week @ 2024-04-29 9/week @ 2024-05-06 19/week @ 2024-05-13 27/week @ 2024-05-20 4/week @ 2024-05-27 21/week @ 2024-06-03 19/week @ 2024-06-10 15/week @ 2024-06-17 9/week @ 2024-06-24

65 downloads per month
Used in zero4rs

MIT license

13KB
194 lines

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");

Dependencies

~13–24MB
~381K SLoC