Redis Database Migration

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.