pub struct ValkeySessionStore { /* private fields */ }valkey only.Expand description
Valkey-backed session store with optional AES-256-GCM encryption at rest.
Session data is serialized with MessagePack and optionally encrypted before
storage. TTL is managed by Valkey-native key expiry.
Clone is cheap: the inner client and keys are Arc-based.
Implementations§
Source§impl ValkeySessionStore
impl ValkeySessionStore
Sourcepub fn new(client: Client, key: [u8; 32]) -> Self
pub fn new(client: Client, key: [u8; 32]) -> Self
Create an encrypted store using AES-256-GCM (recommended for production).
All session data is encrypted before writing to Valkey and decrypted on read. The 32-byte key should be loaded from a secret store and persisted across restarts.
Sourcepub fn plaintext(client: Client) -> Self
pub fn plaintext(client: Client) -> Self
Create a plaintext store (development/testing only).
Session data is stored unencrypted in Valkey. Do not use in production.
Sourcepub fn encrypted(client: Client, key: [u8; 32]) -> Self
pub fn encrypted(client: Client, key: [u8; 32]) -> Self
Create an encrypted store using AES-256-GCM.
Alias for new.
Sourcepub fn encrypted_with_rotation(
client: Client,
current_key: [u8; 32],
previous_key: [u8; 32],
) -> Self
pub fn encrypted_with_rotation( client: Client, current_key: [u8; 32], previous_key: [u8; 32], ) -> Self
Create an encrypted store with key rotation support.
Writes always use current_key. Reads try current_key first; if
decryption fails, they retry with previous_key. This allows
zero-downtime key rotation: deploy the new key as current, keep the
old key as previous until all sessions have been naturally refreshed
(i.e. one full TTL window), then remove the previous key.
Sourcepub fn with_prefix(self, prefix: impl Into<Arc<str>>) -> Self
pub fn with_prefix(self, prefix: impl Into<Arc<str>>) -> Self
Override the key prefix (default: "axess").
Use this to namespace sessions per tenant or application when multiple
services share the same Valkey instance. For multi-tenant setups,
include the tenant ID in the prefix (e.g. "axess:tenant_abc").
Sourcepub fn with_max_payload(self, max_bytes: usize) -> Self
pub fn with_max_payload(self, max_bytes: usize) -> Self
Override the maximum encoded payload size (default: 64 KiB).
Encoded size is checked after serialization (and encryption, if enabled)
but before writing to Valkey. This protects against unbounded growth of
SessionData.custom.
Trait Implementations§
Source§impl Clone for ValkeySessionStore
impl Clone for ValkeySessionStore
Source§fn clone(&self) -> ValkeySessionStore
fn clone(&self) -> ValkeySessionStore
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl HealthCheck for ValkeySessionStore
impl HealthCheck for ValkeySessionStore
Source§impl SessionStore for ValkeySessionStore
impl SessionStore for ValkeySessionStore
Source§async fn prune_expired(&self) -> Result<u64, Self::Error>
async fn prune_expired(&self) -> Result<u64, Self::Error>
Valkey/Redis evicts expired keys natively (active +
passive expiry, see Redis docs §EXPIRE). There is nothing for
the application to sweep; the server already does it. This
returns Ok(0) deliberately, not as the “unsupported” sentinel
the trait once defaulted to.
Source§type Error = ValkeyStoreError
type Error = ValkeyStoreError
Source§async fn load(&self, id: &SessionId) -> Result<Option<SessionData>, Self::Error>
async fn load(&self, id: &SessionId) -> Result<Option<SessionData>, Self::Error>
None if the session
does not exist or has expired.Source§async fn save(
&self,
id: &SessionId,
data: &SessionData,
ttl: Duration,
) -> Result<(), Self::Error>
async fn save( &self, id: &SessionId, data: &SessionData, ttl: Duration, ) -> Result<(), Self::Error>
Source§async fn delete(&self, id: &SessionId) -> Result<(), Self::Error>
async fn delete(&self, id: &SessionId) -> Result<(), Self::Error>
Source§impl Store<SessionId, SessionData> for ValkeySessionStore
impl Store<SessionId, SessionData> for ValkeySessionStore
Source§type Error = ValkeyStoreError
type Error = ValkeyStoreError
StoreError enum for
new backends; legacy wrappers may continue to surface
SqlStoreError / ValkeyStoreError / PostgresStoreError
until each is consolidated.Source§fn get(
&self,
key: &SessionId,
) -> impl Future<Output = Result<Option<SessionData>, Self::Error>> + Send
fn get( &self, key: &SessionId, ) -> impl Future<Output = Result<Option<SessionData>, Self::Error>> + Send
key. Ok(None) when the key is absent
(including TTL-expired); Err only on backend failure.Source§fn put(
&self,
key: &SessionId,
value: &SessionData,
ttl: Duration,
) -> impl Future<Output = Result<(), Self::Error>> + Send
fn put( &self, key: &SessionId, value: &SessionData, ttl: Duration, ) -> impl Future<Output = Result<(), Self::Error>> + Send
key with the given TTL.Source§fn delete(
&self,
key: &SessionId,
) -> impl Future<Output = Result<(), Self::Error>> + Send
fn delete( &self, key: &SessionId, ) -> impl Future<Output = Result<(), Self::Error>> + Send
key. Idempotent; does not error if absent.Source§fn prune_expired(&self) -> impl Future<Output = Result<u64, Self::Error>> + Send
fn prune_expired(&self) -> impl Future<Output = Result<u64, Self::Error>> + Send
Ok(0); backends owning their own
row table (SQLite, Postgres, in-memory) actually delete.Auto Trait Implementations§
impl Freeze for ValkeySessionStore
impl !RefUnwindSafe for ValkeySessionStore
impl Send for ValkeySessionStore
impl Sync for ValkeySessionStore
impl Unpin for ValkeySessionStore
impl UnsafeUnpin for ValkeySessionStore
impl !UnwindSafe for ValkeySessionStore
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.