Redis Delete key

Source: Internet
Author: User

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 //删除当前数据库中的所有Keyflushdb//删除所有数据库中的keyflushall

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.