Skip to content

Commit d0d1cc2

Browse files
committed
AsyncRedisClient: support array of keys for del, workaround for redis-mock
- Unfortunately redis-mock currently has an open issue (yeahoffline/redis-mock#135) and an un-merged fix for it (yeahoffline/redis-mock#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
1 parent ced58ca commit d0d1cc2

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

apigw/src/shared/async-redis-client.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@ export default class AsyncRedisClient {
1111
async get(key: string): Promise<string | null> {
1212
return fromCallback<string | null>((cb) => this.client.get(key, cb))
1313
}
14-
async del(...keys: string[]): Promise<number> {
15-
return fromCallback<number>((cb) => this.client.del(...keys, cb))
14+
// NOTE: redis-mock currently does not support parsing multiple arguments
15+
// (see: https://github.com/yeahoffline/redis-mock/pull/178), so AsyncRedisClient
16+
// should support providing the keys as an array and not use the spread
17+
// operator until this is fixed upstream.
18+
async del(keys: string[]): Promise<number>
19+
async del(...keys: string[]): Promise<number>
20+
async del(keys: string | string[]) {
21+
return fromCallback<number>((cb) => this.client.del(keys, cb))
1622
}
1723
async expire(key: string, seconds: number): Promise<number> {
1824
return fromCallback<number>((cb) => this.client.expire(key, seconds, cb))

0 commit comments

Comments
 (0)