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.
1 2 3 |
Redis-cli-h ip-p Port Keys "*" | Xargs redis-cli-h ip-p Port del//If the REDIS-CLI is not set as a system variable, you need to specify the full path of the REDIS-CLI//such as:/opt/redis/redis-cli Keys "*" | Xargs/opt/redis/redis-cli del |
If you want to specify a Redis database access password, use the following command
1 |
Redis-cli-h ip-p port-a Password Keys "*" | Xargs redis-cli-h ip-p port-a password del |
If you want to access a specific database in Redis, use the following command
1 2 |
The following command specifies a data sequence number of 0, which is the default database redis-cli-h ip-p port-n 0 Keys "*" | Xargs redis-cli-h ip-p port-n 0 del |
Remove all keys
To delete all keys, you can use the FLUSHDB and Flushall commands of Redis
1 2 3 4 |
Delete all keys in the current database Flushdb//Remove key from all databases Flushall |
Note: The keys command can be fuzzy matched, but if the Key contains a space, it will not match, and temporarily did not find a good solution.