方法一 redis-shake
注意:1、两个阿里云账号跨账号迁移,有账号权限限制。
2、redis 版本不一致会报错,没解决。
方法二
python
# coding=utf-8
import redis
redis_from = redis.StrictRedis(host='localhost', port=6379, db=3, password='2021')
redis_to = redis.StrictRedis(host='localhost', port=6379, db=3, password='18cc0eF1265801787ad')
if __name__ == '__main__':
cnt = 0
for k in redis_from.keys():
data_type = redis_from.type(k)
print(data_type)
if data_type == b'string':
v = redis_from.get(k)
redis_to.set(k, v)
elif data_type == b'list':
values = redis_from.lrange(k, 0, -1)
redis_to.lpush(k, values)
elif data_type == b'set':
values = redis_from.smembers(k)
redis_to.sadd(k, values)
elif data_type == b'hash':
keys = redis_from.hkeys(k)
for key in keys:
value = redis_from.hget(k, key)
redis_to.hset(k, key, value)
else:
print('not known type')
cnt = cnt + 1
print('-'*30)
print ('total', cnt)