redis 数据库迁移
时间:2021-07-01 10:21:17
帮助过:2人阅读
redis
redis_from = redis.StrictRedis(host=
‘m.test.gengmei.cc‘, port=6379, db=10
)
redis_to = redis.StrictRedis(host=
‘127.0.0.1‘, port=6379, db=
0)
if __name__ ==
‘__main__‘:
cnt =
0
for k
in redis_from.keys():
data_type =
redis_from.type(k)
if data_type ==
‘string‘:
v =
redis_from.get(k)
redis_to.set(k, v)
elif data_type ==
‘list‘:
values = redis_from.lrange(k, 0, -1
)
redis_to.lpush(k, values)
elif data_type ==
‘set‘:
values =
redis_from.smembers(k)
redis_to.sadd(k, values)
else:
print ‘not known type‘
cnt = cnt + 1
print ‘total‘, cnt
info 命令可以查看 key 的总数量,以确保所有数据都写入成功
# Keyspace
db0:keys=41,expires=0,avg_ttl=0
db10:keys=1,expires=1,avg_ttl=80109567
redis 数据库迁移
标签: