admin_config/
redis_config.rs1use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
24pub struct RedisConfig {
25 pub host: String,
27 pub port: u16,
29 pub username: Option<String>,
31 pub password: Option<String>,
33 pub database: u8,
35 pub max_pool_size: u32,
37 pub connect_timeout: u64,
39}
40
41impl Default for RedisConfig {
42 fn default() -> Self {
43 Self {
44 host: "localhost".to_string(),
45 port: 6379,
46 username: Some("".to_string()),
47 password: Some("".to_string()),
48 database: 0,
49 max_pool_size: 20,
50 connect_timeout: 5,
51 }
52 }
53}
54
55impl RedisConfig {
56 pub fn connection_string(&self) -> String {
60 match (&self.username, &self.password) {
61 (Some(username), Some(password)) => {
62 format!(
63 "redis://{}:{}@{}:{}/{}",
64 username, password, self.host, self.port, self.database
65 )
66 }
67 (None, Some(password)) => {
68 format!("redis://:{}@{}:{}/{}", password, self.host, self.port, self.database)
69 }
70 _ => {
71 format!("redis://{}:{}/{}", self.host, self.port, self.database)
72 }
73 }
74 }
75}