BookSleve Del redis key by wildcard

994 views Asked by At

I saw this example on removing Key from redis usign wildcard

You can delete multiple keys with just one DEL command

DEL key1 key2 key3......


You can also delete all keys matching an expression this way

redis-cli KEYS "temp_cart:user*" | xargs redis-cli DEL

Let's say i have keys : key1a, key2b,key7a, .... and i would like to remove all that starts with key*

how do i tell booksleve to do that? when i pass string into its invalidate function with "keys*" it does not seem to do the trick.

1

There are 1 answers

2
Marc Gravell On BEST ANSWER

Redis does not have a "delete by wildcard" operation. Note also that you should never use KEYS in production. At worst you should use SCAN. Fortunately, BookSleeve and SE.Redis automatically use SCAN when available. To do this, you would have to iterate (via SCAN) and issue multilple DEL commands. Which is, notably, exactly what xargs does in your example.