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 replace() { global $redis_host; global $redis_port; global $redis_scheme; $this->cache = new Predis\Client(array("scheme" => $redis_scheme, "host" => $redis_host, "port" => $redis_port)); $this->cache->connect(); //predis //now promote all other entries $keys = $this->cache->keys("*"); $this->log->info("Promoting data queries..."); $this->log->info("*******************************************"); for($x=0;$xlog->info("Looking up for key: ".$keys[$x]); if (strpos($keys[$x],'STATS')===false) { try { $query = $this->cache->hget($keys[$x],'query'); $persistent= $this->cache->hget($keys[$x],'persistent'); if($query!=null) { $this->log->info("going to replace the results for key: ".$keys[$x]." : \n ".$query."\n"); $fetchMode = $this->cache->hget($keys[$x], 'fetchMode'); $shadowResults = $this->cache->hget($keys[$x],'shadow'); $result = $this->cache->hget($keys[$x], 'results'); $backup = $this->cache->hget($keys[$x], 'backup'); if($shadowResults==null) {$shadowResults=$result;} //$this->log->info("Currently stored backup".$backup); //$this->log->info("With currently stored results".$result ); $this->cache->hmset($keys[$x],array("results" =>$shadowResults,"query" =>$query,"persistent" =>$persistent,"shadow" =>$shadowResults,"fetchMode" =>$fetchMode,"backup" =>$backup)); //$this->log->info(" Promoted Stored Entry : "); } else{ $this->log->info("going to delete the key: ".$keys[$x]); $this->cache->del($keys[$x]); } }//catch catch(Exception $e) { $this->log->error('Error : '.$e->getMessage()); $this->log->info("going to delete problematic key: ".$keys[$x]); $this->cache->del($keys[$x]); } } else { $this->log->info("Ignoring chart key: ".$keys[$x]); if (strpos($keys[$x],'STATS')===false) { //todO here should we delete chart entries so that changes are visible in portal? $this->log->info("going to delete the key: ".$keys[$x]); $this->cache->del($keys[$x]); } } } $this->log->info("All Shadow Entries Promoted Sucessfully!"); $this->cache->quit(); } } ?>