aa_storage_redis/
backend.rs1use aa_storage::Result;
5use deadpool_redis::Pool;
6
7use crate::config::RedisStorageConfig;
8use crate::policy::RedisPolicyStore;
9use crate::pool::build_pool;
10use crate::rate_limit::RedisRateLimitCounter;
11use crate::session::RedisSessionStore;
12
13#[derive(Clone)]
18pub struct RedisBackend {
19 pool: Pool,
20}
21
22impl RedisBackend {
23 pub fn connect(config: &RedisStorageConfig) -> Result<Self> {
28 Ok(Self {
29 pool: build_pool(config)?,
30 })
31 }
32
33 pub fn pool(&self) -> &Pool {
35 &self.pool
36 }
37
38 pub fn sessions(&self) -> RedisSessionStore {
40 RedisSessionStore::new(self.pool.clone())
41 }
42
43 pub fn rate_limiter(&self) -> RedisRateLimitCounter {
45 RedisRateLimitCounter::new(self.pool.clone())
46 }
47
48 pub fn policies(&self) -> RedisPolicyStore {
50 RedisPolicyStore::new(self.pool.clone())
51 }
52}