Delete key in bulk
There is a command DEL that removes a single key in Redis, but it seems there is no instruction to delete the key in bulk, but we can do this with the Linux xargs command.
REDIS-CLI Keys "*" | Xargs redis-cli del // If REDIS-CLI is not set as a system variable, you need to specify the full path of the REDIS-CLI // Example:/opt/redis/redis-cli Keys "*" | Xargs/opt/redis/redis-cli del
If you want to specify a Redis database access port, use the following command
Redis-cli-p 6380 Keys "*" | Xargs redis-cli-p 6380 del // port number replaced by your own
If you want to specify a Redis database access password, use the following command
redis-cli-a Password Keys "*" | Xargs redis-cli-a password del// password replaced by your own
If you want to access a specific database in Redis, use the following command
// The following command specifies that the data sequence number is 0, which is the default database Redis-cli-n 0 Keys "*" | Xargs redis-cli-n 0 del
The above commands can be used together, such as
// Remove Machine Reids all Key,redis with "Pro_" starting at Port 6380 are password
Remove all keys
To delete all keys, you can use the FLUSHDB and Flushall commands of Redis
// Delete all keys in the current database flushdb // Remove key from all databases Flushall
Other
1. If key contains spaces like:
A log message Message1
VIP user Peter
VIP User Mark
VIP user Mary
You can remove them by adding quotation marks
DEL "A log Message"
DEL "VIP user"
However, it is not recommended to use a space in key, preferably using a colon to split the field
such as Vip:user:mary
Some documents use underscores, and the hump should also be
2.
In addition, a Redis del can be deleted in bulk, separated by a space
DEL Key1 Key2
will return the number of successful deletions
(integer) 2
For keys with spaces, they need to be enclosed in quotation marks.
DEL "VIP user Mark" "VIP User Mary"
(integer) 2
This article references: https://www.cnblogs.com/DreamDrive/p/5772198.html
deleting keys in a Redis database in bulk