這篇文章主要介紹了php實現(xiàn)redis數(shù)據(jù)庫指定庫號遷移的方法,涉及對于redis數(shù)據(jù)庫的操作技巧,非常具有實用價值,需要的朋友可以參考下
目前創(chuàng)新互聯(lián)已為千余家的企業(yè)提供了網(wǎng)站建設(shè)、域名、雅安服務(wù)器托管、網(wǎng)站托管運營、企業(yè)網(wǎng)站設(shè)計、南芬網(wǎng)站維護等服務(wù),公司將堅持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
本文實例講述了php實現(xiàn)redis數(shù)據(jù)庫指定庫號遷移的方法,分享給大家供大家參考。具體如下:
redis普通的數(shù)據(jù)庫遷移,只能整個redis
save,或者利用主從,當(dāng)然也可以安裝一個redis-dump,不過比較麻煩,這里提供一種php的腳本,實現(xiàn)指定庫號的遷移,其實也就是遍歷根據(jù)存儲類型,讀出來,插入新庫,效果是這樣:
代碼如下:
[root@localhost
~]#
php
1.php
1/407
101/407
201/407
301/407
401/407
PHP實例代碼如下:
代碼如下:
?php
$from
=
'10.0.2.52:6379/7';
$to
=
'127.0.0.1:6379/7';
$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/$totaln";
}
$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;
}
?
希望本文所述對大家的php程序設(shè)計有所幫助。
把A中的q1倒出來 mysqldump -uadmin1 -padmin111 Q1 Q1.sql
然后再B中新建Q2,create database Q2
應(yīng)用Q2 use Q2
導(dǎo)入Q1 source Q1.sql
賦予用戶 grant all privileges on Q2.* to 'admin2'@localhost identified by 'admin2222'
這樣就可以了!
建表
phinx\bin\phinx.bat migrate -e production
建設(shè) phinx.yml文件
paths:
migrations: %%PHINX_CONFIG_DIR%%\database\migrations
seeds: %%PHINX_CONFIG_DIR%%\database\seeds
environments:
default_migration_table: phinxlog
default_database: development
production:
adapter: mysql
host: localhost
name: jitamin2
user: root
pass: ‘‘
port: 3306
charset: utf8
development:
adapter: mysql
host: localhost
name: development_db
user: root
pass: ‘‘
port: 3306
charset: utf8
testing:
adapter: mysql
host: localhost
name: testing_db
user: root
pass: ‘‘
port: 3306
charset: utf8
數(shù)據(jù)遷移命令如下:
phinx\bin\phinx.bat seed:run -e production
%%PHINX_CONFIG_DIR%%\database\seeds下面的文件示例CreateGroupsTable.php如下:
?php
/*
* This file is part of Jitamin.
*
* Copyright (C) Jitamin Team
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Jitamin\Foundation\Security\Role;
use Phinx\Seed\AbstractSeed;
class UserSeeder extends AbstractSeed
{
/**
* Run Method.
*/
public function run()
{
$data = [
[
‘username‘ = ‘a(chǎn)dmin‘,
‘password‘ = bcrypt(‘a(chǎn)dmin‘),
‘email‘ = ‘a(chǎn)dmin@admin.com‘,
‘role‘ = Role::APP_ADMIN,
],
];
$users = $this-table(‘users‘);
$users-insert($data)
-save();
}
}
網(wǎng)頁題目:php數(shù)據(jù)遷移代碼 php實現(xiàn)數(shù)據(jù)轉(zhuǎn)發(fā)
文章起源:http://www.rwnh.cn/article16/doggdgg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號、云服務(wù)器、、網(wǎng)站內(nèi)鏈、網(wǎng)站營銷、企業(yè)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)