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:
cache.delete(*keys)
solution of Dirk works fine, but make sure keys isn't empty to avoid a redis.exceptions.ResponseError: wrong number of arguments for 'del' command
.
If you are sure that you will always get a result: cache.delete(*cache.keys('prefix:*') )
Btw, for the django-redis you can use the following (from https://niwinz.github.io/django-redis/latest/):
from django.core.cache import cache
cache.delete_pattern("foo_*")
You can use a specific pattern to match all keys and delete them:
import redis
client = redis.Redis(host='192.168.1.106', port=6379,
password='pass', decode_responses=True)
for key in client.keys('prefix:*'):
client.delete(key)