Redis has deleted a single key in the command DEL, but there seems to be no bulk delete key instructions, but we can use the Linux xargs instructions to complete this action.
Copy Code code as follows:
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
such as:/opt/redis/redis-cli Keys "*" | Xargs/opt/redis/redis-cli del
If you want to specify the Redis database access password, use the following command:
Copy Code code as follows:
redis-cli-a Password Keys "*" | Xargs redis-cli-a Password del
If you want to access a specific database in Redis, use the following command:
Copy Code code as follows:
The following command specifies that the data ordinal number is 0, that is, the default database
Redis-cli-n 0 Keys "*" | Xargs redis-cli-n 0 del
Remove all key
To remove all keys, you can use the Redis flushdb and Flushall commands:
Copy Code code as follows:
Delete all keys in the current database
Flushdb
Delete key in all databases
Flushall
Note: The keys command can be fuzzy matching, but if the Key contains spaces, it will not match, temporarily did not find a good solution.