_host = $config['host']; } if (isset($config['port'])) { $this->_port = $config['port']; } if (isset($config['timeout'])) { $this->_timeout = $config['timeout']; } if (isset($config['prefix'])) { $this->_prefix = $config['prefix']; } $this->_cache = new Redis(); if (!$this->_cache->connect($this->_host, $this->_port)) { // dont use fatal here since we can go in an infinite loop echo 'Could not connect to redisd server'; CRM_Utils_System::civiExit(); } if (CRM_Utils_Constant::value('CIVICRM_DB_CACHE_PASSWORD')) { $this->_cache->auth(CIVICRM_DB_CACHE_PASSWORD); } } /** * @param $key * @param $value * * @return bool * @throws Exception */ public function set($key, &$value) { if (!$this->_cache->set($this->_prefix . $key, serialize($value), $this->_timeout)) { CRM_Core_Error::fatal("Redis set failed, wondering why?, $key", $value); return FALSE; } return TRUE; } /** * @param $key * * @return mixed */ public function get($key) { $result = $this->_cache->get($this->_prefix . $key); return ($result === FALSE) ? NULL : unserialize($result); } /** * @param $key * * @return mixed */ public function delete($key) { return $this->_cache->delete($this->_prefix . $key); } /** * @return mixed */ public function flush() { return $this->_cache->flushDB(); } }