摘要:環(huán)境的是遷移處理了個(gè)批處理處理完成了遷移遷移結(jié)束剩余長(zhǎng)度每次遷移一千個(gè)遷移的的值重復(fù)了清空輸入的是連接連接帶接收的庫(kù)遷移到新庫(kù)值長(zhǎng)度是
環(huán)境的是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), "個(gè)") if cursor != 0: print(cursor, "批處理") moveHash(cursor) else: print(cursor, "處理完成了") # 遷移list def moveList(): length = r.llen(key) if length == 0: print(key, "---list遷移結(jié)束---剩余長(zhǎng)度", length) else: # 每次遷移一千個(gè) 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的值重復(fù)了", 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 帶接收的庫(kù) 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 + "遷移到新庫(kù)") if keyType == "hash": cursor = r.hlen(key) print(" key值長(zhǎng)度是 + ", cursor) moveHash(0) if keyType == "list": moveList()
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://m.specialneedsforspecialkids.com/yun/43822.html
閱讀 2604·2021-11-17 09:33
閱讀 3958·2021-10-19 11:46
閱讀 916·2021-10-14 09:42
閱讀 2261·2021-09-22 15:41
閱讀 4233·2021-09-22 15:20
閱讀 4638·2021-09-07 10:22
閱讀 2314·2021-09-04 16:40
閱讀 821·2019-08-30 15:52