成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

Redis中redis-cluster如何刪除指定的key-創(chuàng)新互聯(lián)

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

創(chuàng)新互聯(lián)建站專注于企業(yè)營銷型網(wǎng)站、網(wǎng)站重做改版、昂昂溪網(wǎng)站定制設(shè)計、自適應(yīng)品牌網(wǎng)站建設(shè)、html5、成都商城網(wǎng)站開發(fā)、集團公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)公司、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計等建站業(yè)務(wù),價格優(yōu)惠性價比高,為昂昂溪等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。

需要從redis-cluster中刪除指定的key

循環(huán)每個主節(jié)點的版本:

  1. [root@ip-172-31-39-42 ~]# more delkey-single.py

  2. # encoding: utf-8

  3. import redis

  4. import random

  5. import string

  6. import rediscluster

  7. import time

  8. 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']

  9. def del_keys_without_pipe(newhost):

  10.     pool = redis.ConnectionPool(host=newhost, port=6379, db=0,password='inH7HkD7iXoxKZCi')

  11.     r = redis.StrictRedis(connection_pool=pool)

  12.     start_time = time.time()

  13.     result_length = 0

  14.     for key in r.scan_iter(match='user:*:type:*:news:msg', count=100):

  15.         if r.ttl(key) == -1:     如果未設(shè)置過期時間

  16.            print key

  17.    #       r.delete(key)

  18.         result_length += 1

  19.     print "normal ways end at:", time.time() - start_time

  20.     print newhost,"normal ways delete numbers:", result_length

  21. for i in all_nodes:

  22.         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

鏈接集群版本

  1. [root@ip-172-31-39-42 ~]# more delkey-cluster.py

  2. # encoding: utf-8

  3. import redis

  4. import random

  5. import string

  6. import rediscluster

  7. import time

  8. def del_keys_without_pipe():

  9.     startup_nodes = [{"host": "172.31.39.42", "port": 6379,"db":0}]

  10.     r = rediscluster.StrictRedisCluster(startup_nodes=startup_nodes, password='inH7HkD7iXoxKZCi')

  11.     start_time = time.time()

  12.     result_length = 0

  13.     for key in r.scan_iter(match='user:*:type:*:news:msg', count=100):

  14.     #        r.delete(key)

  15.         result_length += 1

  16.     print "normal ways end at:", time.time() - start_time

  17.     print "normal ways delete numbers:", result_length

  18. del_keys_without_pipe()

以上是“Redis中redis-cluster如何刪除指定的key”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道!

當(dāng)前標(biāo)題:Redis中redis-cluster如何刪除指定的key-創(chuàng)新互聯(lián)
分享地址:http://jinyejixie.com/article26/ccsdjg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、云服務(wù)器、網(wǎng)站改版全網(wǎng)營銷推廣、定制開發(fā)網(wǎng)站排名

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)公司
秦安县| 宜春市| 苍溪县| 无极县| 肇源县| 五原县| 台南市| 西平县| 建平县| 盐亭县| 会昌县| 额敏县| 郧西县| 青铜峡市| 二连浩特市| 义马市| 栾川县| 怀仁县| 尉氏县| 尉犁县| 遵化市| 饶河县| 江永县| 普安县| 筠连县| 临沧市| 化德县| 东至县| 如皋市| 修水县| 榆树市| 法库县| 成安县| 定边县| 东兰县| 年辖:市辖区| 梁山县| 临海市| 花莲市| 开江县| 集安市|