Skip to content

Commit

Permalink
AsyncRedisClient: support array of keys for del, workaround for redis…
Browse files Browse the repository at this point in the history
…-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
  • Loading branch information
mikkopiu committed May 10, 2021
1 parent ced58ca commit d0d1cc2
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions apigw/src/shared/async-redis-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ export default class AsyncRedisClient {
async get(key: string): Promise<string | null> {
return fromCallback<string | null>((cb) => this.client.get(key, cb))
}
async del(...keys: string[]): Promise<number> {
return fromCallback<number>((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<number>
async del(...keys: string[]): Promise<number>
async del(keys: string | string[]) {
return fromCallback<number>((cb) => this.client.del(keys, cb))
}
async expire(key: string, seconds: number): Promise<number> {
return fromCallback<number>((cb) => this.client.expire(key, seconds, cb))
Expand Down

0 comments on commit d0d1cc2

Please sign in to comment.