Remove all Redis keys

Source: Internet
Author: User
Tags delete key redis
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.

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.