redis delete wildcard

delete_redis_keys(["sof_36", "sof_249", "sof_34"])

def delete_redis_keys(keys):
    for key in keys:

Is there a way for me to delete all keys starting with sof_ ?
delete_redis_keys(["sof_*"]) of sorts ?

Hey there!
Not from django cache neither directly from a redis command.
You must first list the keys and later delete them.
You can grab some working examples here on this gist on how to do that using the redis-cli, you can wrap this call from your django-code using something like subprocess.

1 Like

It seems this works - r.delete(*r.keys("sof_*"))

If you look into the gist that i had sent, you’ll see that this approach has a drawback on large amounts of entries. You’ll be fine for a few hundreds of keys, otherwise i suggest that you take a deeper look into the discussion there.

I see that SCAN is used for a pattern - I’ll look into it.