Skip to main content

SessionStore

Trait SessionStore 

Source
pub trait SessionStore: Send + Sync {
    // Required methods
    fn read(&self, session_id: &str) -> Option<HashMap<String, Value>>;
    fn write(&self, session_id: &str, data: HashMap<String, Value>);
    fn destroy(&self, session_id: &str);

    // Provided method
    fn exists(&self, session_id: &str) -> bool { ... }
}
Expand description

Session 存储后端 trait

抽象会话数据的持久化层,对齐 PHP think\session\Driver 抽象类。 实现方需提供基于 session_id 的命名空间隔离。

§PHP 对齐

abstract class Driver implements SessionHandlerInterface {
    // read($sessionId): string
    // write($sessionId, $data): bool
    // destroy($sessionId): bool
    // gc($maxLifetime): int
}

Required Methods§

Source

fn read(&self, session_id: &str) -> Option<HashMap<String, Value>>

读取指定 session_id 的所有数据

返回 None 表示 session 不存在或已过期。

Source

fn write(&self, session_id: &str, data: HashMap<String, Value>)

写入指定 session_id 的完整数据

对齐 PHP write($sessionId, $data)

Source

fn destroy(&self, session_id: &str)

销毁指定 session_id

对齐 PHP destroy($sessionId)

Provided Methods§

Source

fn exists(&self, session_id: &str) -> bool

检查指定 session_id 是否存在

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§