search
Homephp教程php手册PHP导出Redis数据到另一个Redis中的方法

 这篇文章主要介绍了使用PHP导出Redis数据到另一个Redis中的方法,需要的朋友可以参考下

从某个 Redis db 导出数据到另一个 Redis db 的PHP脚本:   代码如下:$from = '127.0.0.1:6200/6'; $to   = '127.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, $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; }  
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor