国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

利用python 遷移單個redis的key。

Cciradih / 718人閱讀

摘要:環境的是遷移處理了個批處理處理完成了遷移遷移結束剩余長度每次遷移一千個遷移的的值重復了清空輸入的是連接連接帶接收的庫遷移到新庫值長度是

環境的是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

相關文章

發表評論

0條評論

最新活動
閱讀需要支付1元查看
<