Ejemplo 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;
 }
Ejemplo n.º 2
0
 /**
  * Test getting a unique identifier
  */
 public function testGetUniqueId()
 {
     $this->assertNotEmpty($this->redis->getUniqueId());
 }