1
|
<?php
|
2
|
|
3
|
require_once('./js/log4php/Logger.php');
|
4
|
require_once('./paths.php');
|
5
|
require_once('./MYDB.php');
|
6
|
|
7
|
|
8
|
$rc = new MigrateCache();
|
9
|
$rc->migrate();
|
10
|
|
11
|
class MigrateCache {
|
12
|
// private $log;
|
13
|
// private $cache = null; //predis
|
14
|
|
15
|
public function migrate()
|
16
|
{
|
17
|
$log;
|
18
|
$cache;
|
19
|
|
20
|
$redis_host ='localhost';
|
21
|
$redis_port= '6379';
|
22
|
$redis_scheme='tcp';
|
23
|
|
24
|
$log = Logger::getLogger("test");
|
25
|
Logger::configure('./js/log4php/log4php.xml');
|
26
|
|
27
|
if(class_exists("Predis\Client")){
|
28
|
try {
|
29
|
//todo changed timeout from 0 to -1
|
30
|
$cache = new Predis\Client(array("scheme" => $redis_scheme,"host" => $redis_host,"port" => $redis_port,"read_write_timeout" => -1));
|
31
|
$log->info("redis host: ".$redis_host." and redis port: ".$redis_port);
|
32
|
} catch(Exception $e) {
|
33
|
$log->error("Error connecting to Redis server: ".$e->getMessage());
|
34
|
$cache = null;
|
35
|
}
|
36
|
}
|
37
|
else{ $log->info("cache does not exist"); //predis
|
38
|
exit;}
|
39
|
|
40
|
|
41
|
|
42
|
$keys = $cache->keys("*");
|
43
|
|
44
|
for($x=0;$x<count($keys);$x++) {
|
45
|
|
46
|
if ((strpos($keys[$x],'chart')===false)&&(strpos($keys[$x],'table')===false)&&(strpos($keys[$x],'STATS')===false) )
|
47
|
{
|
48
|
|
49
|
try
|
50
|
{
|
51
|
|
52
|
$values=$cache->hgetall($keys[$x]);
|
53
|
|
54
|
//TODO here add flag for persistent
|
55
|
|
56
|
{
|
57
|
|
58
|
$pers = array('persistent' => 'true');
|
59
|
$value=$values+$pers;
|
60
|
echo "id ";
|
61
|
echo $keys[$x];
|
62
|
echo "\n";
|
63
|
|
64
|
echo "peristent ";
|
65
|
echo $value['persistent'];
|
66
|
echo "\n";
|
67
|
|
68
|
//echo $value['results'];
|
69
|
|
70
|
$cache->hmset($keys[$x],$value);
|
71
|
$log->info("id : ".$keys[$x]);
|
72
|
$log->info("res: ".$cache->hget($keys[$x],"results"));
|
73
|
|
74
|
}
|
75
|
|
76
|
|
77
|
}
|
78
|
catch(Exception $e) {
|
79
|
|
80
|
$log->error('Error : '.$e->getMessage());
|
81
|
}
|
82
|
break;
|
83
|
}
|
84
|
else
|
85
|
{ $log->info("Ignoring chart key: ".$keys[$x]); }
|
86
|
|
87
|
|
88
|
}
|
89
|
|
90
|
$cache->quit();
|
91
|
$log->info("Done migtating ! ");
|
92
|
|
93
|
}
|
94
|
}
|
95
|
?>
|