Skip to main content

kojin_redis/
config.rs

1/// Redis broker configuration.
2#[derive(Debug, Clone)]
3pub struct RedisConfig {
4    /// Redis connection URL (e.g., "redis://127.0.0.1:6379").
5    pub url: String,
6    /// Connection pool size.
7    pub pool_size: usize,
8    /// Key prefix for all Redis keys.
9    pub key_prefix: String,
10}
11
12impl Default for RedisConfig {
13    fn default() -> Self {
14        Self {
15            url: "redis://127.0.0.1:6379".to_string(),
16            pool_size: 10,
17            key_prefix: "kojin".to_string(),
18        }
19    }
20}
21
22impl RedisConfig {
23    pub fn new(url: impl Into<String>) -> Self {
24        Self {
25            url: url.into(),
26            ..Default::default()
27        }
28    }
29
30    pub fn with_pool_size(mut self, size: usize) -> Self {
31        self.pool_size = size;
32        self
33    }
34
35    pub fn with_prefix(mut self, prefix: impl Into<String>) -> Self {
36        self.key_prefix = prefix.into();
37        self
38    }
39}