@[TOC] 记一次pika数据迁移到codis
import redis def hash_fnv1a_64(s): UINT32_MAX = 2 ** 32 FNV_64_INIT = 0xcbf29ce484222325 % UINT32_MAX FNV_64_PRIME = 0x100000001b3 % UINT32_MAX hval = FNV_64_INIT for c in s: hval = hval ^ ord(c) hval = (hval * FNV_64_PRIME) % UINT32_MAX return hval def cleanKey(key, conn): conn.delete(key) def scanKey(conn): r = conn num = 0 n, l = r.scan(0, count=500) while True: for i in l: modula = hash_fnv1a_64(i) % count if modula != index: cleanKey(i,r) if n == 0: return n, l = r.scan(n, count=500) if __name__ == "__main__": host = sys.argv[1] port = int(sys.argv[2]) count = int(sys.argv[3]) index = int(sys.argv[4]) r = redis.Redis(host=host, port=port) scanKey(r)
#key检查脚本 import redis import sys def scanKey(conn): r = conn num = 0 n, l = r.scan(0, count=500) while True: for i in l: s = c.exists(i) if int(s) == 0: print i if n == 0: return n,l = r.scan(n,count=500) if __name__ == "__main__": c = redis.Redis(host='172.16.6.182',prot=19001)#codis client host = sys.argv[1] port = int(sys.argv[2]) r = redis.Redis(host=host,port=port) scanKey(r)最后附一个迁移到codis的实际运行图