pub struct SaStorageDistributedStorage { /* private fields */ }Expand description
基于 SaStorage 的分布式 Session 存储实现 把分布式 Session、登录索引、服务凭证统一持久化到任意 SaStorage 后端(Redis / 内存 / 数据库)
§存储键格式
- Session:
{prefix}dsession:{session_id} - 登录索引:
{prefix}dsession:index:{login_id} - 服务凭证:
{prefix}dservice:{service_id}
Implementations§
Trait Implementations§
Source§impl DistributedSessionStorage for SaStorageDistributedStorage
impl DistributedSessionStorage for SaStorageDistributedStorage
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,
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,
保存 Session
- 写入会话本体(带 TTL,由后端控制过期)
- 更新登录索引(永久保存,去重;过期 session 在读取时被过滤清理)
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,
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,
按 session_id 读取会话 未找到或已过期返回 None
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,
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,
删除会话
- 先读出会话以获得 login_id(用于维护索引)
- 删除会话本体
- 从登录索引中移除该 session_id(无剩余则删除整个索引键)
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,
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,
获取某用户全部会话 顺带清理索引中已过期/丢失的 session_id(best-effort 清理,避免索引无限膨胀)
Source§fn save_credential<'life0, 'async_trait>(
&'life0 self,
credential: ServiceCredential,
) -> Pin<Box<dyn Future<Output = Result<(), SaTokenError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn save_credential<'life0, 'async_trait>(
&'life0 self,
credential: ServiceCredential,
) -> Pin<Box<dyn Future<Output = Result<(), SaTokenError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
保存服务凭证(永久保存)
Source§fn get_credential<'life0, 'life1, 'async_trait>(
&'life0 self,
service_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<ServiceCredential>, SaTokenError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_credential<'life0, 'life1, 'async_trait>(
&'life0 self,
service_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<ServiceCredential>, SaTokenError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
按 service_id 读取服务凭证 未找到返回 None
Auto Trait Implementations§
impl !RefUnwindSafe for SaStorageDistributedStorage
impl !UnwindSafe for SaStorageDistributedStorage
impl Freeze for SaStorageDistributedStorage
impl Send for SaStorageDistributedStorage
impl Sync for SaStorageDistributedStorage
impl Unpin for SaStorageDistributedStorage
impl UnsafeUnpin for SaStorageDistributedStorage
Blanket Implementations§
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
Mutably borrows from an owned value. Read more