Skip to content

Commit

Permalink
redis - fixing error again on calling clear with empty keys (#977)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredwray committed Jan 8, 2024
1 parent 11c7fd1 commit d7d5e11
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/redis/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ class KeyvRedis<Value = any> extends EventEmitter {
} else {
const pattern = 'sets:*';
const keys: string[] = await this.redis.keys(pattern);
await this.redis.unlink(keys);
if (keys.length > 0) {
await this.redis.unlink(keys);
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions packages/redis/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,16 @@ test.serial('del should work when not using useRedisSets', async t => {

t.is(value, undefined);
});

test.serial('clear method with empty keys should not error', async t => {
const keyv = new KeyvRedis(redisURI);

await t.notThrowsAsync(keyv.clear());
});

test.serial('clear method when useRedisSets is false and empty keys should not error', async t => {
const options = {useRedisSets: false};
const keyv = new KeyvRedis(options);

await t.notThrowsAsync(keyv.clear());
});

0 comments on commit d7d5e11

Please sign in to comment.