InMemoryDistributedStorage

Struct InMemoryDistributedStorage 

Source
pub struct InMemoryDistributedStorage { /* private fields */ }
Expand description

In-memory distributed session storage implementation 内存分布式 Session 存储实现

For testing and development purposes 用于测试和开发目的

Implementations§

Source§

impl InMemoryDistributedStorage

Source

pub fn new() -> Self

Create a new in-memory storage 创建新的内存存储

Trait Implementations§

Source§

impl Default for InMemoryDistributedStorage

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl DistributedSessionStorage for InMemoryDistributedStorage

Source§

fn save_session<'life0, 'async_trait>( &'life0 self, session: DistributedSession, _ttl: Option<Duration>, ) -> Pin<Box<dyn Future<Output = Result<(), SaTokenError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Save session to memory storage | 保存会话到内存存储

§Implementation Details | 实现细节
  1. Stores session in main HashMap by session_id 在主 HashMap 中按 session_id 存储会话
  2. Updates login_index for quick user lookup 更新 login_index 以快速查找用户
§Note | 注意

TTL is ignored in memory storage (for simplicity). In production, use Redis or similar with built-in TTL support. 内存存储中忽略 TTL(为简化实现)。 在生产环境中,使用 Redis 或类似的内置 TTL 支持的存储。

Source§

fn get_session<'life0, 'life1, 'async_trait>( &'life0 self, session_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<DistributedSession>, SaTokenError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get session from memory storage | 从内存存储获取会话

§Returns | 返回
  • Ok(Some(session)) - Session found | 找到会话
  • Ok(None) - Session not found | 未找到会话
Source§

fn delete_session<'life0, 'life1, 'async_trait>( &'life0 self, session_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), SaTokenError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Delete session from memory storage | 从内存存储删除会话

§Implementation Details | 实现细节
  1. Removes session from main HashMap 从主 HashMap 中移除会话
  2. Removes session_id from login_index 从 login_index 中移除 session_id
  3. Cleans up empty index entries 清理空的索引条目
Source§

fn get_sessions_by_login_id<'life0, 'life1, 'async_trait>( &'life0 self, login_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<DistributedSession>, SaTokenError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get all sessions for a user | 获取用户的所有会话

§Implementation Details | 实现细节
  1. Looks up session_ids in login_index 在 login_index 中查找 session_ids
  2. Retrieves full session data for each session_id 为每个 session_id 检索完整的会话数据
  3. Filters out any missing sessions (cleanup) 过滤掉任何缺失的会话(清理)
§Returns | 返回

Vector of all active sessions for the user 用户所有活跃会话的向量

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more