/sessions

General sessions module for web services

Primary LanguageRustApache License 2.0Apache-2.0

Sessions

General sessions module for web services


Safety! Docs.rs docs Crates.io version Download Discord Twitter: @_fundon

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.