821537186e
- Reorganized import statements in adapter tests for better readability - Replaced or_insert_with(Vec::new) with or_default() in test closures - Updated Cargo.lock with new dependency versions and checksums - Added TLS features to tonic dependency configuration - Included sqlx, chrono, and uuid dependencies with specific features - Added jsonwebtoken and arc-swap as project dependencies - Reformatted assertion statements to comply with line length limits - Adjusted base64 import order in engine codec module - Updated protobuf include statement formatting
43 lines
1.3 KiB
Rust
43 lines
1.3 KiB
Rust
pub mod memory;
|
|
pub mod redis;
|
|
|
|
use async_trait::async_trait;
|
|
use thiserror::Error;
|
|
|
|
#[derive(Error, Debug)]
|
|
pub enum SessionError {
|
|
#[error("Redis error: {0}")]
|
|
Redis(String),
|
|
#[error("Session not found: {0}")]
|
|
NotFound(String),
|
|
#[error("Serialization error: {0}")]
|
|
Serialization(String),
|
|
#[error("Session expired: {0}")]
|
|
Expired(String),
|
|
}
|
|
|
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
|
pub struct SessionInfo {
|
|
pub sid: String,
|
|
pub transport: String,
|
|
pub state: String,
|
|
pub server_id: String,
|
|
pub created_at: u64,
|
|
pub last_ping: u64,
|
|
}
|
|
|
|
#[async_trait]
|
|
pub trait SessionStoreTrait: Send + Sync + 'static {
|
|
async fn create(&self, sid: &str, transport: &str, server_id: &str)
|
|
-> Result<(), SessionError>;
|
|
async fn get(&self, sid: &str) -> Result<Option<SessionInfo>, SessionError>;
|
|
async fn set_state(&self, sid: &str, state: &str) -> Result<(), SessionError>;
|
|
async fn set_transport(&self, sid: &str, transport: &str) -> Result<(), SessionError>;
|
|
async fn update_ping(&self, sid: &str) -> Result<(), SessionError>;
|
|
async fn remove(&self, sid: &str) -> Result<(), SessionError>;
|
|
async fn exists(&self, sid: &str) -> Result<bool, SessionError>;
|
|
}
|
|
|
|
pub use memory::InMemorySessionStore;
|
|
pub use redis::RedisSessionStore;
|