In a Redis database, if you have a large number of keys that start or end with some fields, you will typically use the command keys for fuzzy matching. But when we wanted to delete the volume-specific keys, we were worried because Redis did not provide the relevant commands. So how do we operate to achieve the desired effect?
(1) Delete a single key
del key
If you know the name of a limited number of keys, the following operations can also be implemented in bulk operations
del key1 key2 Key3 ....
When the number of keys reaches a certain number, this method is obviously unrealistic.
Note:the Redis command line uses spaces to divide the key value by default, and if there is a space in the morning of a key, the key with the space must be enclosed in quotation marks:
127.0.0.1:6379>del "first key""second key "
(2) Delete key in bulk
Bulk Delete key, we can use the Linux xargs instruction to complete this action
"a * " del Note: If Redis-cli is not set as a system variable, you need to specify thefull path of the redis-CLI such as:"a*"del
If you want to specify a Redis database access password, use the following command
"a * " del
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 127.0.0.1:6379>redis"a*"del
(3) Delete all keys
To delete all keys, you can use the FLUSHDB and Flushall commands of Redis
Delete all keys in the current database flushdb // Delete key from all databases
deleting keys in a Redis database in bulk