0

I am trying to remove multiple keys from a Redis instance based on a specified key pattern. However, unique to many of the other answers I've seen on SO, I need to do this entirely within the Redis console without the use of any other scripting or Bash. The reason being that I need to execute this from within the Console functionality of the Azure Cache for Redis portal. I am able to select the keys I want using SCAN 0 MATCH *mypattern* but, I don't know of any way to "pipe" this to the DEL command.

1
  • 1
    Check this answer. I hope this may help you. Commented May 1, 2022 at 19:40

1 Answer 1

1

In case this is helpful to anyone else, here is the answer I found that worked for me.

EVAL "return redis.call('del', unpack(redis.call('scan', 0, ‘MATCH', ARGV[1])[2]))" 0 *mypattern*

The inner redis.call('scan') command finds all keys matching *mypattern* (any key with "mypattern" anywhere in it). The second index position of the return value of this command is the list of the keys which is then unpacked and passed to the outer redis.call('del') command which deletes the objects from the cache.

Note that this will return an error if there are no keys matching the pattern. This was ok for my use case so I did not explore it further, but there may be a way around this.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.