redis / redis

Redis is an in-memory database that persists on disk. The data model is key-value, but many different kind of values are supported: Strings, Lists, Sets, Sorted Sets, Hashes, Streams, HyperLogLogs, Bitmaps.
http://redis.io
Other
66.89k stars 23.79k forks source link

Delete multiple keys at once #4153

Open Roam-Cooper opened 7 years ago

Roam-Cooper commented 7 years ago

Surely by now people have realised that deleting multiple keys at once (something like del key:*) is incredibly useful, especially for devs like me that have to hunt down the same verbose LUA script every single time I want to delete a handful of keys while testing.

Is deleting multiple keys a feature that can be added? Redis has been around for a long enough time now, and I haven't seen anything on this when I've checked other than "it isn't possible".

alimousazy commented 7 years ago

I can work on this, do you mean delete with hash keys ?

alimousazy commented 7 years ago

https://redis.io/commands/hdel

alimousazy commented 7 years ago

what about if the user want to use key:* as a key, how this should work ?

alimousazy commented 7 years ago

maybe you can delete the hash entirely if you want to delete all the keys

mgravell commented 7 years ago

Frankly, if you have a bunch of related keys that commonly need to die together, I wonder if you should simply use a hash anyway. Then a single del kills all of them and it avoids sharing issues on cluster etc. You can still read/write/remove single items via hset / hget / hdel.

Del is already varadic but you need to know the keys you want to delete. "del x y z" works fine. I doubt a "dellike foo*" would ever be added due to both the sharding (cluster) issue, and the performance impact (see: "keys" command).

Asalle commented 5 years ago

what about if the user want to use key:* as a key, how this should work ?

escape it

tobiasBora commented 1 month ago

@mgravell The hash works nicely if you are not already using a hash. But since you cannot nest hashes, it's not always applicable.