diff --git a/packages/backend-rs/index.d.ts b/packages/backend-rs/index.d.ts index 433e80999c..0c75def671 100644 --- a/packages/backend-rs/index.d.ts +++ b/packages/backend-rs/index.d.ts @@ -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 diff --git a/packages/backend-rs/src/config/server.rs b/packages/backend-rs/src/config/server.rs index edfdf6109c..720e1a9c49 100644 --- a/packages/backend-rs/src/config/server.rs +++ b/packages/backend-rs/src/config/server.rs @@ -82,8 +82,7 @@ pub struct RedisConfig { pub tls: Option, #[serde(default)] pub db: u32, - #[serde(default)] - pub prefix: String, + pub prefix: Option, } #[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, diff --git a/packages/backend-rs/src/database/redis.rs b/packages/backend-rs/src/database/redis.rs index 8652c6b53c..e717201f95 100644 --- a/packages/backend-rs/src/database/redis.rs +++ b/packages/backend-rs/src/database/redis.rs @@ -39,7 +39,7 @@ pub fn redis_conn() -> Result { #[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)]