1#![forbid(unsafe_code)]
2
3mod backends;
4
5pub mod error;
6pub mod inmemory;
7pub mod mapping;
8pub mod store;
9
10pub use error::{ErrorCode, GreenticError, SessionResult};
11pub use greentic_types::{ReplyScope, SessionData, SessionKey};
12pub use store::SessionStore;
13
14#[derive(Debug, Clone)]
16pub enum SessionBackendConfig {
17 InMemory,
19 #[cfg(feature = "redis")]
21 RedisUrl(String),
22 #[cfg(feature = "redis")]
24 RedisUrlWithNamespace { url: String, namespace: String },
25}
26
27pub fn create_session_store(config: SessionBackendConfig) -> SessionResult<Box<dyn SessionStore>> {
29 match config {
30 SessionBackendConfig::InMemory => Ok(Box::new(inmemory::InMemorySessionStore::new())),
31 #[cfg(feature = "redis")]
32 SessionBackendConfig::RedisUrl(url) => {
33 let store = backends::redis::RedisSessionStore::from_url(&url)?;
34 Ok(Box::new(store))
35 }
36 #[cfg(feature = "redis")]
37 SessionBackendConfig::RedisUrlWithNamespace { url, namespace } => {
38 let store =
39 backends::redis::RedisSessionStore::from_url_with_namespace(&url, namespace)?;
40 Ok(Box::new(store))
41 }
42 }
43}