#![forbid(unsafe_code)]
mod backends;
pub mod error;
pub mod inmemory;
pub mod mapping;
pub mod store;
pub use error::{ErrorCode, GreenticError, SessionResult};
pub use greentic_types::{ReplyScope, SessionData, SessionKey};
pub use store::SessionStore;
#[derive(Debug, Clone)]
pub enum SessionBackendConfig {
InMemory,
#[cfg(feature = "redis")]
RedisUrl(String),
#[cfg(feature = "redis")]
RedisUrlWithNamespace { url: String, namespace: String },
}
pub fn create_session_store(config: SessionBackendConfig) -> SessionResult<Box<dyn SessionStore>> {
match config {
SessionBackendConfig::InMemory => Ok(Box::new(inmemory::InMemorySessionStore::new())),
#[cfg(feature = "redis")]
SessionBackendConfig::RedisUrl(url) => {
let store = backends::redis::RedisSessionStore::from_url(&url)?;
Ok(Box::new(store))
}
#[cfg(feature = "redis")]
SessionBackendConfig::RedisUrlWithNamespace { url, namespace } => {
let store =
backends::redis::RedisSessionStore::from_url_with_namespace(&url, namespace)?;
Ok(Box::new(store))
}
}
}