摘要:環境的是遷移處理了個批處理處理完成了遷移遷移結束剩余長度每次遷移一千個遷移的的值重復了清空輸入的是連接連接帶接收的庫遷移到新庫值長度是
環境的是python3 / pip3
import sys import redis # 遷移hash def moveHash(cursor): cursor, data = r.hscan(key, cursor) for eachKey in data: rNew.hset(key, eachKey, data[eachKey]) print(key, "---處理了---", len(data), "個") if cursor != 0: print(cursor, "批處理") moveHash(cursor) else: print(cursor, "處理完成了") # 遷移list def moveList(): length = r.llen(key) if length == 0: print(key, "---list遷移結束---剩余長度", length) else: # 每次遷移一千個 start = length - 1000; if start < 0: start = 0 data = r.lrange(key, start, -1) pl = r.pipeline(); for eachI in data: setAdd = r.sadd("ordernokey_move", eachI); if setAdd == 1: pl.rpush("aaaaaaa", eachI) else: print("遷移的key的值重復了", eachI) pl.execute() if start == 0: # 清空 r.ltrim(key, 1, 0) r.ltrim(key, 0, start - 1) moveList() ############################ key = sys.argv[1] print("輸入的key是:" + key) # ip = "47.254.149.109" # password = "Kikuu2018" ip1 = "115.236.170.78" password1 = "kikuu2018" ip2 = "115.236.170.78" password2 = "kikuu2018" # 連接redis r = redis.Redis(host=ip1, password=password1, port=6379, db=0, decode_responses=True) # 連接redis 帶接收的庫 rNew = redis.Redis(host=ip2, password=password2, port=6379, db=0, decode_responses=True) keyType = r.type(key) if keyType == "string": rNew.set(key, r.get(key)) print("key=" + key + "遷移到新庫") if keyType == "hash": cursor = r.hlen(key) print(" key值長度是 + ", cursor) moveHash(0) if keyType == "list": moveList()
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/43822.html
閱讀 2595·2021-11-17 09:33
閱讀 3936·2021-10-19 11:46
閱讀 910·2021-10-14 09:42
閱讀 2252·2021-09-22 15:41
閱讀 4204·2021-09-22 15:20
閱讀 4628·2021-09-07 10:22
閱讀 2302·2021-09-04 16:40
閱讀 811·2019-08-30 15:52