Use PHP to export Redis data to another Redis code. PHP script for exporting data from a Redisdb to another Redisdb: Copy the code as follows: $ from127.0.0.1: 62006; $ to127.0.0.1: 62008; $ from_redisredis_init ($ from the PHP script for exporting data from a Redis db to another Redis db:
The code is as follows:
$ From = '1970. 0.0.1: 80801 ';
$ To = '127. 0.0.1: 8080 ';
$ From_redis = redis_init ($ from );
$ To_redis = redis_init ($ );
$ 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, $ val );
}
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 to export data from 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...