deleting keys in a Redis database in bulk

Source: Internet
Author: User
Tags delete key

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

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.