Example #1
0
 /**
  * Handle loading the redis client.
  *
  * @access  public
  * @return  void
  */
 public function getClient($retries = 1)
 {
     try {
         if (!empty($this->client) && $this->client->isConnected()) {
             return true;
         }
         $scheme = empty($this->config['scheme']) ? 'tcp' : $this->config['scheme'];
         $host = empty($this->config['host']) ? '127.0.0.1' : $this->config['host'];
         $port = empty($this->config['port']) ? '6379' : $this->config['port'];
         $prefix = empty($this->config['prefix']) ? NULL : $this->config['prefix'];
         $this->client = new \Predis\Client(array('prefix' => rtrim($prefix, ':') . ':', 'scheme' => $scheme, 'host' => $host, 'port' => $port));
         // TODO: handle authentication if necessary
         if (!empty($this->config['password'])) {
             $this->client->auth($this->config['password']);
         }
         return true;
     } catch (Exception $e) {
         // TODO: better error handling
         error_log($e->getMessage());
         error_log(print_r($e, true));
     }
     // handle retries on failure
     if ($retries < self::MAX_RETRIES) {
         sleep($retries + 1);
         return $this->getClient($retries + 1);
     }
     return false;
 }