Boss Let's move all the data from Redis on one machine to another machine
Check it out. You can copy an RDB file, which is only for migrating to a new library and migrating to a library that is in use.
It is also possible to set the master slave, and the data will be automatically synchronized and simple
The stupidest and easiest way to think of it is to write a script that reads all the data from the original library and writes it to another library.
ImportRedisredis_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 forKinchRedis_from.keys (): Data_type=Redis_from.type (k)ifData_type = ='string': v=Redis_from.get (k) Redis_to.set (k, v)elifData_type = ='List': Values= Redis_from.lrange (k, 0,-1) Redis_to.lpush (k, values)elifData_type = ='Set': Values=redis_from.smembers (k) Redis_to.sadd (k, values)Else: Print 'Not known type'CNT= cnt + 1Print ' Total'Cnt
The info command can view the total number of keys to ensure that all data is written successfully
# Keyspace
Db0:keys=41,expires=0,avg_ttl=0
db10:keys=1,expires=1,avg_ttl=80109567
Redis Database Migration