From eb2e86997d47249aa31b703598de13ab2eb96caa Mon Sep 17 00:00:00 2001 From: rtkay123 Date: Tue, 3 Feb 2026 13:45:46 +0200 Subject: feat: add cache --- src/config/mod.rs | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'src/config/mod.rs') diff --git a/src/config/mod.rs b/src/config/mod.rs index 7495b22..e64ae5c 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1,13 +1,15 @@ +pub mod cache; mod cli; mod logging; mod port; pub use cli::Cli; -#[cfg(feature = "oauth")] -use secrecy::SecretString; use serde::Deserialize; use url::Url; -use crate::config::logging::LogLevel; +use crate::config::{ + cache::{CacheConfig, RedisVariant}, + logging::LogLevel, +}; #[derive(Default, Deserialize, Debug, PartialEq, Eq)] #[serde(rename_all = "kebab-case")] @@ -23,6 +25,8 @@ pub struct Config { #[serde(default)] pub database: DatabaseOptions, #[serde(default)] + pub cache: CacheConfig, + #[serde(default)] pub server: Api, #[serde(default)] #[cfg(feature = "oauth")] @@ -65,7 +69,7 @@ pub struct OAuth { #[serde(rename_all = "kebab-case")] pub struct DiscordOauth { pub client_id: String, - pub client_secret: SecretString, + pub client_secret: secrecy::SecretString, #[serde(default = "discord_token_url")] pub token_url: Url, #[serde(default = "discord_auth_url")] @@ -94,7 +98,7 @@ impl Default for OAuth { #[cfg(feature = "oauth-discord")] discord: DiscordOauth { client_id: String::default(), - client_secret: SecretString::default(), + client_secret: secrecy::SecretString::default(), token_url: discord_token_url(), auth_url: discord_auth_url(), }, @@ -175,6 +179,7 @@ impl Config { pub fn merge_with_cli(&mut self, cli: &Cli) { let server = &mut self.server; let dsn = &mut self.database; + let cache = &mut self.cache; if let Some(port) = cli.port { server.port = port; @@ -195,6 +200,26 @@ impl Config { if let Some(db_url) = &cli.db { dsn.url = db_url.clone(); } + + if let Some(c) = cli.cache.as_ref().and_then(|v| v.cache_url.clone()) { + cache.redis_dsn = c; + } + + if let Some(c) = cli.cache.as_ref().and_then(|v| v.cache_pooled) { + cache.pooled = c; + } + + if let Some(c) = cli.cache.as_ref().and_then(|v| v.cache_max_conn) { + cache.max_connections = c; + } + + if let Some(c) = cli.cache.as_ref().and_then(|v| v.cache_type.clone()) { + cache.kind = match c { + cli::cache::RedisVariant::Clustered => RedisVariant::Clustered, + cli::cache::RedisVariant::NonClustered => RedisVariant::NonClustered, + cli::cache::RedisVariant::Sentinel => cache.kind.clone(), + }; + } } } -- cgit v1.2.3