Skip to main content

Module store

Module store 

Source
Expand description

The storage contract and the built-in stores.

The guard holds all security logic; a store only persists records and performs two operations atomically: SessionStore::apply (rotate, mark used, update) and the lookups. Implement SessionStore for your own backend and run the store_conformance! (feature testing) suite against it.

Structs§

MemoryStore
Keeps everything in memory behind one mutex. Nothing survives a restart and nothing is shared between processes, so use it for tests, development and single-instance apps only.
PgStorepostgres
Stores sessions in PostgreSQL through a sqlx PgPool. Shared safely by any number of processes; rotations are single transactions with a conditional update, and a partial unique index guarantees at most one current token per session.
Rotation
Replace the current token with a new one.
SessionRecord
A stored session.
SessionUpdate
Everything one request changes, applied atomically by SessionStore::apply.
TokenLookup
Result of SessionStore::find_by_token.
TokenRecord
A stored token.
ValkeyStorevalkey
A SessionStore on Valkey or Redis, standalone or Cluster.

Enums§

ClaimScope
What an event claim is deduplicated by. See SessionStore::claim_event.
Supersede
Which token a Rotation replaces. Each variant is a condition evaluated atomically against the session’s current token; if it does not hold, nothing rotates.

Traits§

SessionStore
Session persistence.

Functions§

session_bucket
The bucket a session id belongs to: its last byte. Sharded stores keep all of a session’s records in this bucket, and the guard sets that byte when it creates the id.
token_bucket
The bucket a token belongs to: the first byte of its hash. A session’s tokens share its session_bucket when the store is sharded.