Exemplo n.º 1
0
 /**
  * Returns the wrapped Redis client instance.
  *
  * This method is called from AbstractRedisWrapper, who uses it to call the desired method directly
  * on the wrapped redis, rather than using call_user_func().
  * The command and key are passed into the method to allow for some logic within the implementations
  * of this method.
  *
  * @param string $command the current command
  * @param string|null $key the current key if available, null otherwise. Commands that operate on
  * multiple keys will pass their keys as a comma separated string.
  * @throws Exception when an error happens during connecting
  * @return Redis
  */
 protected function getWrappedRedis($command, $key = null)
 {
     // if we don't have a client yet, we never connected, so let's do it now
     if (!$this->client) {
         // gotta make sure the app actually tried to connect first
         if (!$this->connectWasCalled) {
             throw new Exception('call connect() or pconnect() first');
         }
         if (!($this->persistent ? $this->conn->pconnect($this->host, $this->port, $this->timeout) : $this->conn->connect($this->host, $this->port, $this->timeout))) {
             throw new Exception('could not connect to ' . $this->conn->getUniqueId() . ' params: ' . (!empty($this->host) ? $this->host . ':' . $this->port : 'none'));
         }
         $this->client = $this->conn->getClient();
     }
     return $this->client;
 }
Exemplo n.º 2
0
 /**
  * This method uses the stored connection parameters to connect an instance.
  *
  * @param Connection $conn
  * @return bool
  */
 protected function connectInstance(Connection $conn)
 {
     // connect() and pconnect() can throw exceptions, which we just want to treat as connection failures
     // TODO: really? can they?
     try {
         $res = $this->origPersistent ? $conn->pconnect($this->origHost, $this->origPort, $this->origTimeout) : $conn->connect($this->origHost, $this->origPort, $this->origTimeout);
     } catch (ConnectionError $e) {
         return false;
     }
     if ($this->origDbindex) {
         $res = $res && $conn->select($this->origDbindex);
     }
     return $res;
 }
Exemplo n.º 3
0
 /**
  * Test connecting with a timeout provided. Won't really give sensible results, because
  * we can't control how long the server takes to reply. In fact it might even be unstable
  * on Jenkins, but whatever.
  */
 public function testConnectWithTimeout()
 {
     $this->redis->disconnect();
     $this->assertTrue($this->redis->connect('localhost', 6379, 1.0));
     $this->assertTrue($this->redis->isconnected());
 }