How to export Redis data to another Redis using PHP _ PHP Tutorial

Source: Internet
Author: User
How does PHP export Redis data to another Redis instance. This article mainly introduces how to use PHP to export Redis data to another Redis. For more information, see the PHP script for exporting data from a Redisdb to another Redisdb: this article mainly introduces how to use PHP to export Redis data to another Redis instance. For more information, see

PHP script for exporting data from a Redis db to another Redis db: the code is as follows: $ from = '2017. 0.0.1: 6200/6 '; $ to = '2017. 0.0.1: 6200/8 '; $ from_redis = redis_init ($ from); $ to_redis = redis_init ($ to); $ keys = $ from_redis-> keys ('*'); $ count = 0; $ total = count ($ keys); foreach ($ keys as $ key) {if (++ $ count % 100 = 1) {echo "$ count/$ total \ n" ;}$ type = $ from_redis-> type ($ key); switch ($ type) {case Redis: REDIS_STRING: $ val = $ from_redis-> get ($ key ); $ To_redis-> set ($ key, $ val); break; case Redis: REDIS_LIST: $ list = $ from_redis-> lRange ($ key, 0,-1 ); foreach ($ list as $ val) {$ to_redis-> rPush ($ key, $ val);} break; case Redis: REDIS_HASH: $ hash = $ from_redis-> hGetAll ($ key); $ to_redis-> hMSet ($ key, $ hash); break; case Redis: REDIS_ZSET: $ zset = $ from_redis-> zRange ($ key, 0,-1, true); foreach ($ zset as $ val => $ score) {$ to_redis-> zAdd ($ key, $ score, $ va L);} break;} function redis_init ($ conf) {$ redis = new Redis (); preg_match ('/^ ([^:] + )(: [0-9] + )? \/(. + )? /', $ Conf, $ ms); $ host = $ ms [1]; $ port = trim ($ ms [2],': '); $ db = $ ms [3]; $ redis-> connect ($ host, $ port); $ redis-> select ($ db); return $ redis ;}

The PHP script used by the supervisor to export data from a Redis db to another Redis db :...

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.