成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

利用python 遷移單個redis的key。

Cciradih / 727人閱讀

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

環(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), "個")
    if cursor != 0:
        print(cursor, "批處理")
        moveHash(cursor)
    else:
        print(cursor, "處理完成了")


# 遷移list
def moveList():
    length = r.llen(key)
    if length == 0:
        print(key, "---list遷移結(jié)束---剩余長度", 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的值重復(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  帶接收的庫
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()

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/43822.html

相關(guān)文章

發(fā)表評論

0條評論

閱讀需要支付1元查看
<