Skip to content

Commit

Permalink
build(deps): update dependency redis to v4 (#13260)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Rhys Arkins <rhys@arkins.net>
  • Loading branch information
4 people committed Jan 19, 2022
1 parent da0bbf2 commit 995dd0e
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 139 deletions.
4 changes: 2 additions & 2 deletions lib/util/cache/package/decorator.spec.ts
Expand Up @@ -10,9 +10,9 @@ jest.mock('./file');
describe('util/cache/package/decorator', () => {
const spy = jest.fn(() => Promise.resolve());

beforeAll(() => {
beforeAll(async () => {
memCache.init();
packageCache.init({ cacheDir: os.tmpdir() });
await packageCache.init({ cacheDir: os.tmpdir() });
});

beforeEach(() => {
Expand Down
6 changes: 3 additions & 3 deletions lib/util/cache/package/index.spec.ts
Expand Up @@ -9,18 +9,18 @@ describe('util/cache/package/index', () => {
expect(await set('test', 'some-key', 'some-value', 5)).toBeUndefined();
});
it('sets and gets file', async () => {
init({ cacheDir: 'some-dir' });
await init({ cacheDir: 'some-dir' });
expect(
await set('some-namespace', 'some-key', 'some-value', 1)
).toBeUndefined();
expect(await get('some-namespace', 'unknown-key')).toBeUndefined();
});
it('sets and gets redis', async () => {
init({ redisUrl: 'some-url' });
await init({ redisUrl: 'some-url' });
expect(
await set('some-namespace', 'some-key', 'some-value', 1)
).toBeUndefined();
expect(await get('some-namespace', 'unknown-key')).toBeUndefined();
expect(cleanup({ redisUrl: 'some-url' })).toBeUndefined();
expect(await cleanup({ redisUrl: 'some-url' })).toBeUndefined();
});
});
8 changes: 4 additions & 4 deletions lib/util/cache/package/index.ts
Expand Up @@ -39,9 +39,9 @@ export async function set(
await cacheProxy.set(namespace, key, value, minutes);
}

export function init(config: AllConfig): void {
export async function init(config: AllConfig): Promise<void> {
if (config.redisUrl) {
redisCache.init(config.redisUrl);
await redisCache.init(config.redisUrl);
cacheProxy = {
get: redisCache.get,
set: redisCache.set,
Expand All @@ -55,8 +55,8 @@ export function init(config: AllConfig): void {
}
}

export function cleanup(config: AllConfig): void {
export async function cleanup(config: AllConfig): Promise<void> {
if (config?.redisUrl) {
redisCache.end();
await redisCache.end();
}
}
27 changes: 14 additions & 13 deletions lib/util/cache/package/redis.ts
@@ -1,17 +1,18 @@
/* istanbul ignore file */
import { WrappedNodeRedisClient, createNodeRedisClient } from 'handy-redis';
import { DateTime } from 'luxon';
import { createClient } from 'redis';
import { logger } from '../../../logger';

let client: WrappedNodeRedisClient | undefined;
let client: ReturnType<typeof createClient> | undefined;

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

export function end(): void {
export async function end(): Promise<void> {
try {
client?.nodeRedis?.end(true); // TODO: Why is this not supported by client directly? (#9714)
// https://github.com/redis/node-redis#disconnecting
await client?.disconnect();
} catch (err) {
logger.warn({ err }, 'Redis cache end failed');
}
Expand Down Expand Up @@ -60,23 +61,23 @@ export async function set(
value,
expiry: DateTime.local().plus({ minutes: ttlMinutes }),
}),
['EX', ttlMinutes * 60]
{ EX: ttlMinutes * 60 }
);
}

export function init(url: string): void {
export async function init(url: string): Promise<void> {
if (!url) {
return;
}
logger.debug('Redis cache init');
client = createNodeRedisClient({
client = createClient({
url,
retry_strategy: (options) => {
if (options.error) {
logger.error({ err: options.error }, 'Redis cache error');
}
// Reconnect after this time
return Math.min(options.attempt * 100, 3000);
socket: {
reconnectStrategy: (retries) => {
// Reconnect after this time
return Math.min(retries * 100, 3000);
},
},
});
await client.connect();
}
2 changes: 1 addition & 1 deletion lib/workers/global/index.ts
Expand Up @@ -138,7 +138,7 @@ export async function start(): Promise<number> {
return 2;
}
} finally {
globalFinalize(config);
await globalFinalize(config);
logger.debug(`Renovate exiting`);
}
const loggerErrors = getProblems().filter((p) => p.level >= ERROR);
Expand Down
6 changes: 3 additions & 3 deletions lib/workers/global/initialize.ts
Expand Up @@ -49,12 +49,12 @@ export async function globalInitialize(
await checkVersions();
config = await initPlatform(config);
config = await setDirectories(config);
packageCache.init(config);
await packageCache.init(config);
limitCommitsPerRun(config);
setEmojiConfig(config);
return config;
}

export function globalFinalize(config: RenovateConfig): void {
packageCache.cleanup(config);
export async function globalFinalize(config: RenovateConfig): Promise<void> {
await packageCache.cleanup(config);
}
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -167,7 +167,6 @@
"good-enough-parser": "1.1.7",
"got": "11.8.3",
"handlebars": "4.7.7",
"handy-redis": "2.3.1",
"hasha": "5.2.2",
"ignore": "5.2.0",
"ini": "2.0.0",
Expand All @@ -189,7 +188,7 @@
"p-queue": "6.6.2",
"parse-diff": "0.9.0",
"parse-link-header": "2.0.0",
"redis": "3.1.2",
"redis": "4.0.1",
"registry-auth-token": "4.2.1",
"remark": "13.0.0",
"remark-github": "10.1.0",
Expand Down

0 comments on commit 995dd0e

Please sign in to comment.