Esempio n. 1
0
 public function pconnect()
 {
     $this->conn = phpiredis_pconnect($this->host, $this->port);
     return $this->conn ? true : false;
 }
Esempio n. 2
0
 /**
  * @param float $timeout
  * @param bool $persistent
  * @return bool
  * @throws \Plista\Core\Redis\ConnectionParametersMissingException
  */
 private function doConnect($timeout = 0.0, $persistent = false)
 {
     if (empty($this->host)) {
         throw new ConnectionParametersMissingException();
     }
     // phpiredis expects the timeout in ms
     $timeout = (int) ($timeout * 1000);
     if ($persistent) {
         if ($timeout == 0) {
             $this->connection = phpiredis_pconnect($this->host, $this->port);
         } else {
             $this->connection = phpiredis_pconnect($this->host, $this->port, $timeout);
         }
     } else {
         if ($timeout == 0) {
             $this->connection = phpiredis_connect($this->host, $this->port);
         } else {
             $this->connection = phpiredis_connect($this->host, $this->port, $timeout);
         }
     }
     if (!$this->connection) {
         return false;
     }
     // not everyone has the most current phpiredis extension installed
     if (function_exists('phpiredis_set_error_handler')) {
         phpiredis_set_error_handler($this->connection, array($this, 'handleError'));
     }
     return true;
 }