log = Logger::getLogger("__CLASS__"); Logger::configure('./js/log4php/log4php.xml'); if(class_exists("Predis\Client")){ try { //todo changed timeout from 0 to -1 $this->cache = new Predis\Client(array("scheme" => $redis_scheme,"host" => $redis_host,"port" => $redis_port,"read_write_timeout" => -1)); $this->log->info("redis host: ".$redis_host." and redis port: ".$redis_port); } catch(Exception $e) { $this->log->error("Error connecting to Redis server: ".$e->getMessage()); $this->cache = null; } } else{ $this->log->info("cache does not exist"); //predis exit; } } public function migrate($redis_remote_host,$redis_remote_port) {global $redis_host; global $redis_port; global $redis_scheme; global $host; $backupKeys=$this->cache->hkeys('STATS_NUMBERS'); $this->log->info("migrating Stat Numbers from ".$redis_host." to ".$redis_remote_host." on ".$redis_remote_port); try { //todo changed timeout from 0 to -1 $this->remotecache = new Predis\Client(array("scheme" => $redis_scheme,"host" => $redis_remote_host,"port" => $redis_port,"read_write_timeout" => -1)); $this->log->info("redis host: ".$redis_remote_host." and redis port: ".$redis_remote_port); } catch(Exception $e) { $this->log->error("Error connecting to Redis server: ".$e->getMessage()); $this->cache = null; } $this->remotecache->connect(); for($x=0;$xcache->hget('STATS_NUMBERS',$key); $this->log->info("saving : ".$key." : ".$value); $this->remotecache->hmset('STATS_NUMBERS',$key,$value); $this->log->info("query saved : ".$this->remotecache->hget('STATS_NUMBERS',$key)); } $this->log->info("migrating Shadow Stat Numbers from ".$redis_host." to ".$redis_remote_host." on ".$redis_remote_port); $backupKeys=$this->cache->hkeys('SHADOW_STATS_NUMBERS'); for($x=0;$xcache->hget('SHADOW_STATS_NUMBERS',$key); $this->log->info("saving : ".$key." : ".$value); $this->remotecache->hmset('SHADOW_STATS_NUMBERS',$key,$value); $this->log->info("query saved : ".$this->remotecache->hget('SHADOW_STATS_NUMBERS',$key)); } //***************************** $this->log->info("Migrating data queries..."); $this->log->info("*******************************************"); $keys = $this->cache->keys("*"); for($x=0;$xcache->hgetall($keys[$x]); $this->log->info("Moving..."); $this->remotecache->hmset($keys[$x],$values); $this->log->info("id : ".$keys[$x]); //$this->log->info("res: ".$this->remotecache->hget($keys[$x],"results"));} } catch(Exception $e) {$this->log->error('Error : '.$e->getMessage());} } else {$this->log->info("Ignoring chart key: ".$keys[$x]); }} $this->cache->quit(); $keys = $this->remotecache->keys("*"); $keys = $this->remotecache->keys("*"); for($x=0;$xremotecache->hget($keys[$x],"persistent")!='true') {try{ $this->log->info("Deleting...".$keys[$x]." for pers ".$this->remotecache->hget($keys[$x],"persistent")); $this->remotecache->del($keys[$x]); } catch(Exception $e) { $this->log->error('Error : '.$e->getMessage()); } } } $this->remotecache->quit(); $this->log->info("Done migrating ! "); } } //$rc = new MigrateCache(); //$rc->migrate(); ?>