I am having a hash set in redis names as = "match/123/result"
I am adding entries to set using "HSET" and retrieving all entries at a time using "HGETALL"
now, I want to flush this hash set, but there is no command like "HDELALL"
so I am using "DEL" to remove the hash set name itself, in this case I fire the command like this -
DEL match/123/result
Could find only this approach to remove everything at once. Is there any other solution ?
Redis HDEL command is used to remove the specified fields from the hash stored at a key and ignored the specified keys that do not exist within this hash. It is treated as an empty hash if the key does not exist, and this command returns 0.
Redis Commands There are two major commands to delete the keys present in Redis: FLUSHDB and FLUSHALL. We can use the Redis CLI to execute these commands. The FLUSHDB command deletes the keys in a database. And the FLUSHALL command deletes all keys in all databases.
We can use keys command like below to delete all the keys which match the given patters “ user*" from the Redis. Note :- Not recommended on production Redis instance. I have written Lua script to delete multiple keys by pattern . Script uses the scan command to delete the Redis cache key in incremental iteration.
Redis HMSET command is used to set the specified fields to their respective values in the hash stored at the key. This command overwrites any existing fields in the hash. If the key does not exist, a new key holding a hash is created.
If you want to delete or flush the 'myhash' hash.
Please use the command below:
redis-cli redis> del myhash
Hope it will solve the problem.
Here's a ruby-based way to remove all the keys in a Hash via a single, pipelined request:
def hdelall(key) r = Redis.new keys = r.hgetall(key).keys r.pipelined do keys.each do |k| r.hdel key, k end end end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With