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
tls?: TlsConfig
db: number
prefix: string
prefix?: string
}
export interface TlsConfig {
host: string
@ -165,6 +165,7 @@ export interface Config {
version: string
host: string
hostname: string
redisKeyPrefix: string
scheme: string
wsScheme: string
apiUrl: string

View File

@ -82,8 +82,7 @@ pub struct RedisConfig {
pub tls: Option<TlsConfig>,
#[serde(default)]
pub db: u32,
#[serde(default)]
pub prefix: String,
pub prefix: Option<String>,
}
#[derive(Clone, Debug, PartialEq, Deserialize)]
@ -217,6 +216,7 @@ pub struct Config {
pub version: String,
pub host: String,
pub hostname: String,
pub redis_key_prefix: String,
pub scheme: String,
pub ws_scheme: String,
pub api_url: String,
@ -315,6 +315,13 @@ fn load_config() -> Config {
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 {
url: server_config.url,
port: server_config.port,
@ -361,6 +368,7 @@ fn load_config() -> Config {
version,
host,
hostname,
redis_key_prefix,
scheme,
ws_scheme,
client_entry: manifest,

View File

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