Redis the method of bulk Delete key _redis

Source: Internet
Author: User
Tags delete key redis

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.

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.