In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly shows you the "Redis redis-cluster how to delete the specified key", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "Redis redis-cluster how to delete the specified key" this article.
You need to remove the version of each master node of the specified key loop from redis-cluster:
[root@ip-172-31-39-42] # more delkey-single.py
# encoding: utf-8
Import redis
Import random
Import string
Import rediscluster
Import time
All_nodes= (172.31.39.42) 172.31.36.10 (172.31.47.157) 172.31.36.49 (172.31.40.169)
Def del_keys_without_pipe (newhost):
Pool = redis.ConnectionPool (host=newhost, port=6379, db=0,password='inH7HkD7iXoxKZCi')
R = redis.StrictRedis (connection_pool=pool)
Start_time = time.time ()
Result_length = 0
For key in r.scan_iter (match='user:*:type:*:news:msg', count=100):
If r.ttl (key) =-1: if expiration time is not set
Print key
# r.delete (key)
Result_length + = 1
Print "normal ways end at:", time.time ()-start_time
Print newhost, "normal ways delete numbers:", result_length
For i in all_nodes:
Del_keys_without_pipe (I)
Note: circular links can only link to the master node, if the link slave node will report the following error:
> > for key in r.scan_iter (count=10):
... If r.ttl (key) =-1:
... Print key
...
Traceback (most recent call last):
File "", line 2, in
File "/ usr/lib/python2.7/site-packages/redis/client.py", line 1231, in ttl
Return self.execute_command ('TTL', name)
File "/ usr/lib/python2.7/site-packages/redis/client.py", line 668, in execute_command
Return self.parse_response (connection, command_name, * * options)
File "/ usr/lib/python2.7/site-packages/redis/client.py", line 680, in parse_response
Response = connection.read_response ()
File "/ usr/lib/python2.7/site-packages/redis/connection.py", line 629, in read_response
Raise response
Redis.exceptions.ResponseError: MOVED 12752 172.31.32.234:6379
Link Cluster version
[root@ip-172-31-39-42] # more delkey-cluster.py
# encoding: utf-8
Import redis
Import random
Import string
Import rediscluster
Import time
Def del_keys_without_pipe ():
Startup_nodes = [{"host": "172.31.39.42", "port": 6379, "db": 0}]
R = rediscluster.StrictRedisCluster (startup_nodes=startup_nodes, password='inH7HkD7iXoxKZCi')
Start_time = time.time ()
Result_length = 0
For key in r.scan_iter (match='user:*:type:*:news:msg', count=100):
# r.delete (key)
Result_length + = 1
Print "normal ways end at:", time.time ()-start_time
Print "normal ways delete numbers:", result_length
Del_keys_without_pipe ()
The above is all the content of the article "how to delete the specified key in redis-cluster in Redis". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.