In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains the "redis batch deletion key value problem how to solve", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's train of thought slowly in depth, together to study and learn "redis batch delete key value problem how to solve" it!
Problems encountered:
In the process of development, you will encounter key that want to delete a certain rule in batch, such as login_logID (ID is a variable). Now you need to delete data such as "login_log*", but redis itself only has a command to batch query a class of key values, but there is no command to delete a class in batch.
Solution:
First query, before deletion, use xargs to pass parameters (xargs can convert pipeline or standard input (stdin) data into command line parameters), execute the query statement first, and delete the query key value and the original del parameter.
Redis-cli KEYS key* (search criteria) | xargs redis-cli del
= > [number of results returned after execution]: (integer) 10 [quantity 10]
To do an experiment, first create three key values of the same type
127.0.0.1 set test1 6379 > 1
OK
127.0.0.1 set test2 6379 >
OK
127.0.0.1 set test3 6379 >
OK
Query keys
127.0.0.1 purl 6379 > keys test*
1) "test3"
2) "test2"
3) "test1"
Exit redis and execute the delete command locally
[root@localhost redis] # redis-cli-a password-n 0 (database) keys "test*" | xargs redis-cli-a password-n 0 (database) delWarning: Using a password with'- a'or'- u 'option on the command line interface may not be safe.Warning: Using a password with'-a'or'- u 'option on the command line interface may not be safe. (integer) 3 (number of rows returned)
Principle analysis:
This command first executes the keys command through the redis client, fuzzily searches out all the key, and uses the previously queried key as the input of the del command of the later redis through the xargs command.
It is equivalent to executing redis-cli del test1 test2 test3.
Note: redis condition is required when executing here.-an is the input password,-n is the specified database, and if the redis is not local or there are other changes, you need to add the ip,-p port of the server where h redis is located.
For example
Redis-cli-h 127.0.0.1 (IP address)-p 6379 (port number)-a password-n 1 (the database in which the data is written) KEYS key* (search criteria) | xargs redis-cli (- h (IP address)-p 6379 (port number)-a password-n 1) del
Additional knowledge:
Deletion in redis
The 1.Redis DEL command is used to delete existing keys, and key that does not exist is ignored.
For example:
127.0.0.1 purl 6379 > set hello world
OK
127.0.0.1 purl 6379 > del hello
(integer) 1
However, del can only delete one or more of them, and cannot delete them in batches. It is not applicable when the amount of data to be deleted is too large.
two。 Clear the data from the entire Redis server: flushall
3. Clear all key:flushdb in the current library
Thank you for your reading, the above is the content of "how to solve the problem of redis batch deletion key value". After the study of this article, I believe you have a deeper understanding of how to solve the problem of redis batch deletion key value, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.