fix (backend-rs): use correct Redis key prefix

This commit is contained in:
naskya 2024-04-20 06:52:27 +09:00
parent b017f9ce94
commit f486caf244
No known key found for this signature in database
GPG key ID: 712D413B3A9FED5C
3 changed files with 13 additions and 4 deletions

View file

@ -70,7 +70,7 @@ export interface RedisConfig {
pass?: string pass?: string
tls?: TlsConfig tls?: TlsConfig
db: number db: number
prefix: string prefix?: string
} }
export interface TlsConfig { export interface TlsConfig {
host: string host: string
@ -165,6 +165,7 @@ export interface Config {
version: string version: string
host: string host: string
hostname: string hostname: string
redisKeyPrefix: string
scheme: string scheme: string
wsScheme: string wsScheme: string
apiUrl: string apiUrl: string

View file

@ -82,8 +82,7 @@ pub struct RedisConfig {
pub tls: Option<TlsConfig>, pub tls: Option<TlsConfig>,
#[serde(default)] #[serde(default)]
pub db: u32, pub db: u32,
#[serde(default)] pub prefix: Option<String>,
pub prefix: String,
} }
#[derive(Clone, Debug, PartialEq, Deserialize)] #[derive(Clone, Debug, PartialEq, Deserialize)]
@ -217,6 +216,7 @@ pub struct Config {
pub version: String, pub version: String,
pub host: String, pub host: String,
pub hostname: String, pub hostname: String,
pub redis_key_prefix: String,
pub scheme: String, pub scheme: String,
pub ws_scheme: String, pub ws_scheme: String,
pub api_url: String, pub api_url: String,
@ -315,6 +315,13 @@ fn load_config() -> Config {
None => WorkerConfig { web: 1, queue: 1 }, None => WorkerConfig { web: 1, queue: 1 },
}; };
let redis_key_prefix = if let Some(cache_server) = &server_config.cache_server {
cache_server.prefix.clone()
} else {
server_config.redis.prefix.clone()
}
.unwrap_or(hostname.clone());
Config { Config {
url: server_config.url, url: server_config.url,
port: server_config.port, port: server_config.port,
@ -361,6 +368,7 @@ fn load_config() -> Config {
version, version,
host, host,
hostname, hostname,
redis_key_prefix,
scheme, scheme,
ws_scheme, ws_scheme,
client_entry: manifest, client_entry: manifest,

View file

@ -39,7 +39,7 @@ pub fn redis_conn() -> Result<Connection, RedisError> {
#[inline] #[inline]
/// prefix redis key /// prefix redis key
pub fn key(key: impl ToString) -> String { pub fn key(key: impl ToString) -> String {
format!("{}:{}", CONFIG.redis.prefix, key.to_string()) format!("{}:{}", CONFIG.redis_key_prefix, key.to_string())
} }
#[cfg(test)] #[cfg(test)]