From d0d1cc216b6bf7124c90d8f6f84f9648b9eeee39 Mon Sep 17 00:00:00 2001 From: Mikko Piuhola Date: Mon, 10 May 2021 17:08:09 +0300 Subject: [PATCH] AsyncRedisClient: support array of keys for del, workaround for redis-mock - Unfortunately redis-mock currently has an open issue (https://github.com/yeahoffline/redis-mock/issues/135) and an un-merged fix for it (https://github.com/yeahoffline/redis-mock/pull/178) that means it doesn't support multiple arguments (i.e. spread) for the `.del()` method -> to allow using the mock library in tests add support to AsyncRedisClient for using an array of keys instead of argument-per-key and always provide the keys to the underlying redis client as an array instead of using the spread operator --- apigw/src/shared/async-redis-client.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/apigw/src/shared/async-redis-client.ts b/apigw/src/shared/async-redis-client.ts index 90bfbefd68b..affdf0f5103 100644 --- a/apigw/src/shared/async-redis-client.ts +++ b/apigw/src/shared/async-redis-client.ts @@ -11,8 +11,14 @@ export default class AsyncRedisClient { async get(key: string): Promise { return fromCallback((cb) => this.client.get(key, cb)) } - async del(...keys: string[]): Promise { - return fromCallback((cb) => this.client.del(...keys, cb)) + // NOTE: redis-mock currently does not support parsing multiple arguments + // (see: https://github.com/yeahoffline/redis-mock/pull/178), so AsyncRedisClient + // should support providing the keys as an array and not use the spread + // operator until this is fixed upstream. + async del(keys: string[]): Promise + async del(...keys: string[]): Promise + async del(keys: string | string[]) { + return fromCallback((cb) => this.client.del(keys, cb)) } async expire(key: string, seconds: number): Promise { return fromCallback((cb) => this.client.expire(key, seconds, cb))