diff --git a/docs/usage/self-hosted-configuration.md b/docs/usage/self-hosted-configuration.md index 56a07967d3010c..9d20a034c38d00 100644 --- a/docs/usage/self-hosted-configuration.md +++ b/docs/usage/self-hosted-configuration.md @@ -771,6 +771,11 @@ Used as an alternative to `privateKeyOld`, if you want the key to be read from d Override this object if you want to change the URLs that Renovate links to, e.g. if you have an internal forum for asking for help. +## redisPrefix + +If this value is set then Renovate will prepend this string to the name of all Redis cache entries used in Renovate. +It's only used if `redisUrl` is configured. + ## redisUrl If this value is set then Renovate will use Redis for its global cache instead of the local file system. diff --git a/lib/config/options/index.ts b/lib/config/options/index.ts index 33bf0affa54058..400bb304ddd9d1 100644 --- a/lib/config/options/index.ts +++ b/lib/config/options/index.ts @@ -334,6 +334,13 @@ const options: RenovateOptions[] = [ type: 'string', globalOnly: true, }, + { + name: 'redisPrefix', + description: 'Key prefix for redis cache entries.', + stage: 'global', + type: 'string', + globalOnly: true, + }, { name: 'baseDir', description: diff --git a/lib/config/types.ts b/lib/config/types.ts index 9f3a6d46f85879..b8f0cceb1c28e9 100644 --- a/lib/config/types.ts +++ b/lib/config/types.ts @@ -113,6 +113,7 @@ export interface GlobalOnlyConfig { privateKeyPath?: string; privateKeyPathOld?: string; redisUrl?: string; + redisPrefix?: string; repositories?: RenovateRepository[]; platform?: PlatformId; endpoint?: string; diff --git a/lib/util/cache/package/index.ts b/lib/util/cache/package/index.ts index 80834c30636574..4bc2a94966a35c 100644 --- a/lib/util/cache/package/index.ts +++ b/lib/util/cache/package/index.ts @@ -55,7 +55,7 @@ export async function set( export async function init(config: AllConfig): Promise { if (config.redisUrl) { - await redisCache.init(config.redisUrl); + await redisCache.init(config.redisUrl, config.redisPrefix); cacheProxy = { get: redisCache.get, set: redisCache.set, diff --git a/lib/util/cache/package/redis.ts b/lib/util/cache/package/redis.ts index 4b0fd7c9db58db..408e9263b084c0 100644 --- a/lib/util/cache/package/redis.ts +++ b/lib/util/cache/package/redis.ts @@ -5,9 +5,10 @@ import { logger } from '../../../logger'; import { compress, decompress } from '../../compress'; let client: ReturnType | undefined; +let rprefix: string | undefined; function getKey(namespace: string, key: string): string { - return `${namespace}-${key}`; + return `${rprefix}${namespace}-${key}`; } export async function end(): Promise { @@ -20,7 +21,7 @@ export async function end(): Promise { } async function rm(namespace: string, key: string): Promise { - logger.trace({ namespace, key }, 'Removing cache entry'); + logger.trace({ rprefix, namespace, key }, 'Removing cache entry'); await client?.del(getKey(namespace, key)); } @@ -37,7 +38,7 @@ export async function get( const cachedValue = res && JSON.parse(res); if (cachedValue) { if (DateTime.local() < DateTime.fromISO(cachedValue.expiry)) { - logger.trace({ namespace, key }, 'Returning cached value'); + logger.trace({ rprefix, namespace, key }, 'Returning cached value'); // istanbul ignore if if (!cachedValue.compress) { return cachedValue.value; @@ -49,7 +50,7 @@ export async function get( await rm(namespace, key); } } catch (err) { - logger.trace({ namespace, key }, 'Cache miss'); + logger.trace({ rprefix, namespace, key }, 'Cache miss'); } return undefined; } @@ -60,7 +61,7 @@ export async function set( value: unknown, ttlMinutes = 5, ): Promise { - logger.trace({ namespace, key, ttlMinutes }, 'Saving cached value'); + logger.trace({ rprefix, namespace, key, ttlMinutes }, 'Saving cached value'); // Redis requires TTL to be integer, not float const redisTTL = Math.floor(ttlMinutes * 60); @@ -80,10 +81,14 @@ export async function set( } } -export async function init(url: string): Promise { +export async function init( + url: string, + prefix: string | undefined, +): Promise { if (!url) { return; } + rprefix = prefix ?? ''; logger.debug('Redis cache init'); client = createClient({ url,