I\'m writing a django management command to handle some of our redis caching. Basically, I need to choose all keys, that confirm to a certain pattern (for example: \"prefix:
According to my test, it will costs too much time if I use scan_iter solution (as Alex Toderita wrote).
Therefore, I prefer to use:
from redis.connection import ResponseError
try:
redis_obj.eval('''return redis.call('del', unpack(redis.call('keys', ARGV[1])))''', 0, 'prefix:*')
except ResponseError:
pass
The prefix:* is the pattern.
refers to: https://stackoverflow.com/a/16974060