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.
123 |
redis-cli keys "*" | xargs redis-cli del //如果redis-cli没有设置成系统变量,需要指定redis-cli的完整路径 //如:/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 -a password keys "*" | xargs redis-cli -a password del |
If you want to access a specific database in Redis, use the following command
12 |
//下面的命令指定数据序号为0,即默认数据库 redis-cli -n 0 keys "*" | xargs redis-cli -n 0 del |
Remove all keys
To delete all keys, you can use the FLUSHDB and Flushall commands of Redis
1234 |
//删除当前数据库中的所有Key flushdb //删除所有数据库中的key 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.
Redis Delete key