ioredis delete all keys by pattern

Viewed 20032

I'm using ioredis with express (nodejs) I know that there is a way to delete keys by pattern like this:

redis-cli KEYS "sample_pattern:*" | xargs redis-cli DEL

However, is there a way to do that using ioredis instead?

4 Answers

First select your keys by pattern, then remove them by del method.

const keys = await ioredis.keys('PATTERN:*');

await ioredis.del(keys);
Related