Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: redisPrefix #26398

Merged
merged 8 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/usage/self-hosted-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,11 @@ For TLS/SSL-enabled connections, use rediss prefix

Example URL structure: `rediss://[[username]:[password]]@localhost:6379/0`.

## 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.

## repositories

Elements in the `repositories` array can be an object if you wish to define more settings:
Expand Down
7 changes: 7 additions & 0 deletions lib/config/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions lib/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export interface GlobalOnlyConfig {
privateKeyPath?: string;
privateKeyPathOld?: string;
redisUrl?: string;
redisPrefix?: string;
repositories?: RenovateRepository[];
platform?: PlatformId;
endpoint?: string;
Expand Down
2 changes: 1 addition & 1 deletion lib/util/cache/package/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export async function set(

export async function init(config: AllConfig): Promise<void> {
if (config.redisUrl) {
await redisCache.init(config.redisUrl);
await redisCache.init(config.redisUrl, config.redisPrefix);
cacheProxy = {
get: redisCache.get,
set: redisCache.set,
Expand Down
17 changes: 11 additions & 6 deletions lib/util/cache/package/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { logger } from '../../../logger';
import { compress, decompress } from '../../compress';

let client: ReturnType<typeof createClient> | undefined;
let rprefix: string | undefined;
rarkins marked this conversation as resolved.
Show resolved Hide resolved

function getKey(namespace: string, key: string): string {
return `${namespace}-${key}`;
return `${rprefix}${namespace}-${key}`;
}

export async function end(): Promise<void> {
Expand All @@ -20,7 +21,7 @@ export async function end(): Promise<void> {
}

async function rm(namespace: string, key: string): Promise<void> {
logger.trace({ namespace, key }, 'Removing cache entry');
logger.trace({ rprefix, namespace, key }, 'Removing cache entry');
await client?.del(getKey(namespace, key));
}

Expand All @@ -37,7 +38,7 @@ export async function get<T = never>(
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;
Expand All @@ -49,7 +50,7 @@ export async function get<T = never>(
await rm(namespace, key);
}
} catch (err) {
logger.trace({ namespace, key }, 'Cache miss');
logger.trace({ rprefix, namespace, key }, 'Cache miss');
}
return undefined;
}
Expand All @@ -60,7 +61,7 @@ export async function set(
value: unknown,
ttlMinutes = 5,
): Promise<void> {
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);
Expand All @@ -80,10 +81,14 @@ export async function set(
}
}

export async function init(url: string): Promise<void> {
export async function init(
url: string,
prefix: string | undefined,
): Promise<void> {
if (!url) {
return;
}
rprefix = prefix ?? '';
logger.debug('Redis cache init');
client = createClient({
url,
Expand Down
Loading