Project

General

Profile

1 33141 eri.katsar
<?php
2
require_once('./js/log4php/Logger.php');
3
require_once('./paths.php');
4
require_once('./MYDB.php');
5
6
class MigrateCache {
7
	private $log;
8
	private $db;
9
	private $cache = null; //predis
10
11
public function __construct(){
12
13
		global $redis_host;
14
		global $redis_port;
15
		global $redis_scheme;
16
		global $host;
17
18
                global $db_name;
19
                /*$redis_remote_host='duffy.di.uoa.gr';
20
21
                $redis_remote_port=$redis_port;
22
                $redis_remote_scheme=$redis_scheme;
23
              */
24
               $this->log = Logger::getLogger("__CLASS__");
25
               Logger::configure('./js/log4php/log4php.xml');
26
27
             if(class_exists("Predis\Client")){
28
29
                        try {
30
//todo changed timeout from 0 to -1
31
                        $this->cache = new Predis\Client(array("scheme" => $redis_scheme,"host" => $redis_host,"port" => $redis_port,"read_write_timeout" => -1));
32
                                $this->log->info("redis host: ".$redis_host." and redis port: ".$redis_port);
33
                        } catch(Exception $e) {
34
                                $this->log->error("Error connecting to Redis server: ".$e->getMessage());
35
                                $this->cache = null;
36
                        }
37
                }
38
        else{
39
            $this->log->info("cache does not exist"); //predis
40
                        exit;
41
        }
42
43
44
	}
45
46
public function migrate()
47
{
48
49
               $redis_remote_host='duffy.di.uoa.gr';
50 33176 eri.katsar
              //$redis_host;
51
	     // global $redis_port;
52
               // global $redis_scheme;
53
                //global $host;
54 33141 eri.katsar
55 33176 eri.katsar
                //global $db_name;
56 33141 eri.katsar
57 33176 eri.katsar
                //$redis_remote_port=$redis_port;
58
                //$redis_remote_scheme=$redis_scheme;
59
               // $db_name='stats';
60 33141 eri.katsar
61
62 33176 eri.katsar
//$this->cache->migrate(
63
  //      $redis_remote_host,    # localhost in my example
64
    //    $redis_port,    # 1234
65
      //  'STATS_NUMBERS',                    # The key
66
        //$db_name,-1); //migrate
67 33141 eri.katsar
68 33176 eri.katsar
//$this->cache->executeRaw(["MIGRATE", $redis_remote_host, $redis_port,'STATS_NUMBERS', 'stats', -1]);
69
//response = $client->executeRaw(["MIGRATE", $host, $port, $key, $destination, $timeout]);
70
//Predis\Client::executeRaw()
71 33141 eri.katsar
//$backupKeys=$this->cache->hkeys('STATS_NUMBERS');
72 33176 eri.katsar
 $this->log->info("migrating Stat Numbers...");
73 33141 eri.katsar
74
75 33176 eri.katsar
//nums=$this->cache->hgetall('STATS_NUMBERS');
76
77 33141 eri.katsar
for($x=0;$x<count($backupKeys);$x++)
78
{
79
	$key=$backupKeys[$x];
80
	$value=$this->cache->hget('STATS_NUMBERS',$key);
81 33176 eri.katsar
}
82 33141 eri.katsar
83
//now promote all other entries
84
 $keys = $this->cache->keys("*");
85
 $this->log->info("Migrating data queries...");
86
 $this->log->info("*******************************************");
87
88
 for($x=0;$x<count($keys);$x++) {
89
90
if ((strpos($keys[$x],'chart')===false)&&(strpos($keys[$x],'table')===false)&&(strpos($keys[$x],'STATS')===false) )
91
{
92
 try{
93
94 33176 eri.katsar
$values=$this->cache->hgetall($keys[$x]);
95
96
$persistent= $valuers['persistent'];
97
98
$this->log->info("persistent: ".$persistent);
99
100 33141 eri.katsar
if(($query!=null)&&($persistent))
101
102 33176 eri.katsar
{ }
103 33141 eri.katsar
104 33176 eri.katsar
105
106 33141 eri.katsar
}//catch
107
catch(Exception $e) {
108
109
$this->log->error('Error : '.$e->getMessage());
110
111
}
112
        }
113
 else
114
{ $this->log->info("Ignoring chart key: ".$keys[$x]); }
115
}
116
117
$this->cache->quit();
118
119 33176 eri.katsar
$this->log->info("Done migtating !");
120 33141 eri.katsar
	}
121
122
}
123
124
125
?>