久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

Redis中redis

202次閱讀
沒有評論

共計 2163 個字符,預(yù)計需要花費 6 分鐘才能閱讀完成。

這篇文章主要為大家展示了“Redis 中 redis-cluster 如何刪除指定的 key”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓丸趣 TV 小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“Redis 中 redis-cluster 如何刪除指定的 key”這篇文章吧。

需要從 redis-cluster 中刪除指定的 key
循環(huán)每個主節(jié)點的版本:[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 , 172.31.32.234]

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:      如果未設(shè)置過期時間

 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)

注意:循環(huán)鏈接只能去鏈接主節(jié)點,如果鏈接從節(jié)點會報以下的錯誤:
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

鏈接集群版本 [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()

以上是“Redis 中 redis-cluster 如何刪除指定的 key”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注丸趣 TV 行業(yè)資訊頻道!

正文完
 
丸趣
版權(quán)聲明:本站原創(chuàng)文章,由 丸趣 2023-07-24發(fā)表,共計2163字。
轉(zhuǎn)載說明:除特殊說明外本站除技術(shù)相關(guān)以外文章皆由網(wǎng)絡(luò)搜集發(fā)布,轉(zhuǎn)載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 梨树县| 长沙县| 自治县| 昌邑市| 宁都县| 遵义县| 垣曲县| 正宁县| 阜城县| 綦江县| 太仓市| 历史| 乐平市| 阿鲁科尔沁旗| 大石桥市| 开江县| 凌海市| 桐城市| 凤翔县| 兰坪| 五莲县| 莆田市| 蓝山县| 汕头市| 达日县| 河间市| 石狮市| 屯留县| 保德县| 吐鲁番市| 靖远县| 枝江市| 昌乐县| 崇文区| 株洲县| 沧源| 乐平市| 米林县| 方正县| 周至县| 成安县|