-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimport.php
88 lines (69 loc) · 1.79 KB
/
import.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
function setTimeout($Redis,$key,$expire) {
if ($arr = -1 ) {
$Redis->persist($key);
} elseif($arr > -1) {
$Redis->setTimeout($key,$expire);
}
}
/* 这里替换为连接的实例host和port */
$host = "xxxxxxxxxxx.m.cnhza.kvstore.aliyuncs.com";//改成你自己的
$port = 6379;
/* 这里替换为实例id和实例password */
$user = "xxxxxxxxxxxxxxxx";//改成你自己的
$pwd = "xxxxx";//改成你自己的
$Redis = new redis();
//$Redis->pconnect('127.0.0.1', 6379);
if ($Redis->pconnect($host, $port) == false) {
die($Redis->getLastError());
}
if ($Redis->auth($user . ":" . $pwd) == false) {
die($Redis->getLastError());
}
$file = fopen("redis.json","r");
$arr = array();
while(! feof($file))
{
//echo fgets($file). "<br />";
$arr = json_decode(fgets($file),true);
$Redis->delete($arr['key']);
switch ($arr['type']) {
case $Redis::REDIS_STRING:
echo "string\n";
$Redis->set($arr['key'],$arr['val']);
setTimeout($Redis,$arr['key'],$arr['expire']);
break;
case $Redis::REDIS_HASH:
echo "hash\n";
$Redis->hMset($arr['key'],$arr['val']);
setTimeout($Redis,$arr['key'],$arr['expire']);
break;
case $Redis::REDIS_LIST:
echo "list\n";
foreach($arr['val'] as $v) {
$Redis->rPush($arr['key'], $v);
}
setTimeout($Redis,$arr['key'],$arr['expire']);
break;
case $Redis::REDIS_SET:
echo "set\n";
foreach($arr['val'] as $v) {
$Redis->sAdd($arr['key'], $v);
}
setTimeout($Redis,$arr['key'],$arr['expire']);
break;
case $Redis::REDIS_ZSET:
echo "zset\n";
foreach($arr['val'] as $v =>$score) {
$Redis->zAdd($arr['key'],$score, $v);
}
setTimeout($Redis,$arr['key'],$arr['expire']);
break;
default:
//echo "unknown\n";
continue;
break;
}
}
$Redis->close();
fclose($file);