1

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.

Justin Homes
  • 3,739
  • 9
  • 49
  • 78
  • Booksleve can't do more than Redis itself can. The command redis-cli KEYS "temp_cart:user*" | xargs redis-cli DEL is not sent to Redis as it is. Actually the core of this is executed by the shell as follows: send KEYS "temp_cart:user*" to Redis, read results, loop through each result and execute redis-cli DEL. (I'm not strong in unix, but you should get the idea). I would try to investigate the EVAL command, but not sure as I have never used it. – Alex Nov 11 '14 at 07:11

1 Answers1

0

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.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • so if should not use KEYS _redisClient.Keys.Find(0,"key*") to search for wildcard key match, how can i use SCAN for that in booksleve do you have an example for above question? – Justin Homes Nov 14 '14 at 01:17
  • 1
    @Justin as I stated: BookSleeve and StackExchange.Redis both automatically try to use `SCAN` when it is available; you should be ok using `Find`, but you might want to verify via `MONITOR` that it is using `SCAN` and not `KEYS`. – Marc Gravell Nov 14 '14 at 11:02