I am using Redis hash set to store data in the following format:
hset b1.b2.b3 name test
Now I want to delete this key so I am using the following format:
del b1.b2.*
But it not working so how I delete the Redis key using a pattern?
I am using Redis hash set to store data in the following format:
hset b1.b2.b3 name test
Now I want to delete this key so I am using the following format:
del b1.b2.*
But it not working so how I delete the Redis key using a pattern?
If you'd like to do this via the redis-cli
in bulk, you could consider expiring all the keys based on a specified pattern:
EVAL 'for i, name in ipairs(redis.call("KEYS", <pattern>)) do redis.call("EXPIRE", name, 1); end' 0
Effectively it sets the expiration to 1 second so this should do the trick!
Redis does not provide any method to delete bulk keys. But redis-cli along with xargs can be used to achieve what you are trying to do. See the commands below:
We are scanning redis for a pattern using '--scan' and the output is given to redis-cli again using the xargs method whcih combines all the keys in the scan result and finally we delete all of them using 'del' command.