Esempio n. 1
0
 /**
  * @param $host
  * @param $dbId
  * @param int $port
  * @param null $password
  *
  * @throws \Exception
  */
 public function __construct($host, $dbId, $port = 6379, $password = NULL)
 {
     // redis connector
     $this->_redisInstance = phpiredis_connect($host, $port);
     // select db
     $this->dbSelect($dbId);
     // auth
     if (!is_null($password)) {
         if ($this->dbAuth($password) != 'OK') {
             throw new \Exception('DB: authentication failed.', 401);
         }
     }
 }
Esempio n. 2
0
 public function connect()
 {
     $this->conn = phpiredis_connect($this->host, $this->port);
     return $this->conn ? true : false;
 }
Esempio n. 3
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;
 }