rsession
A simple and flexible session management library for Rust web applications with support for multiple frameworks and storage backends.
Features
- Framework Agnostic: Works with Actix-web, Axum, and Salvo
- Multiple Storage Backends: Redis, Redis Cluster, and Redis Sentinel support
- Session ID Generation: UUID v4, UUID v7, Random, and Random SHA256 options
- Configurable: Expiration times, cookie settings, and refresh strategies
- Type-safe: Built with Rust's strong type system and serde integration
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Feature Flags
Enable specific features based on your needs:
[]
= "0.1.0"
= [
"redis", # Redis storage backend
"redis-cluster", # Redis Cluster support
"redis-sentinel", # Redis Sentinel support
"actix-web", # Actix-web framework integration
"tower", # Axum framework integration
"salvo" # Salvo framework integration
]
Quick Start
Axum Example
use get;
use Router;
use AxumSessionMiddlewareLayer;
use RedisSessionStorage;
use ;
use TcpListener;
async
async
Framework Integrations
Actix-web
use ;
use ActixSessionMiddleware;
use RedisSessionStorage;
use ;
async
async
Salvo
use *;
use ;
use RedisSessionStorage;
use RandKey;
async
async
Configuration
The SessionBuilder allows you to customize session behavior:
let session_builder = new
.key // Cookie name
.expire_time // Session expiration
.path // Cookie path
.domain // Cookie domain
.secure // Secure cookie flag
.http_only // HTTP-only cookie flag
.same_site // SameSite policy
.rand_key // Session ID generation method
.refresh_strategy;
Storage Backends
Redis
let redis = from_url
.create_pool
.unwrap;
let mut store = new;
store.set_prefix; // Optional key prefix
Redis Cluster
let config = from_urls;
let pool = config.create_pool.unwrap;
let store = new;
Redis Sentinel
let config = new;
let pool = config.create_pool.unwrap;
let store = new;
License
This project is licensed under the MIT License - see the LICENSE file for details.