FierySwampshire / sessions

General sessions module for web services

Home Page:https://github.com/trek-rs/sessions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sessions

General sessions module for web services


Features

  • Async/await

  • Easy custom Storages

  • Stores the values in a Map<String, Value> based on serde_json

Example

sessions = { version = "0.1", features = ["memory"] }
use std::sync::Arc;
use sessions::*;

let config = Arc::new(Config {
  cookie: CookieOptions::new(),
  storage: Arc::new(MemoryStorage::new()),
  //storage: Arc::new(RedisStorage::new(RedisClient::open("redis://127.0.0.1")?)),
  generate: Box::new(|| nanoid::nanoid!(32)),
  verify: Box::new(|sid: &str| sid.len() == 32),
});


let session = Session::new(&config.generate(), 0, config.clone());
session.set::<String>("crate", "sessions".to_string());
let val: Option<String> = session.get("crate");
session.remove("crate");
session.clear();

session.save().await;
session.renew().await;
session.destroy().await;

Storages

  • Memory
  • Redis
  • sled
  • Memcached
  • Mongodb
  • PostgreSQL
  • MySQL/MariaDB

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

General sessions module for web services

https://github.com/trek-rs/sessions

License:Apache License 2.0


Languages

Language:Rust 100.0%