isConnected() public method

Returns the current state of the underlying connection.
public isConnected ( ) : boolean
return boolean
Example #1
0
 /**
  * Creates a connect to Redis or Sentinel using the Predis\Client object.  It proxies the connecting and converts
  * specific client exceptions to more generic adapted ones in PSRedis
  *
  * @throws \PSRedis\Exception\ConnectionError
  */
 public function connect()
 {
     try {
         $this->predisClient = $this->predisClientFactory->createClient($this->clientType, $this->getPredisClientParameters());
         $this->predisClient->connect();
         $this->isConnected = $this->predisClient->isConnected();
     } catch (ConnectionException $e) {
         throw new ConnectionError($e->getMessage());
     }
 }
Example #2
0
 /**
  * Create a new Sentinel Monitor.
  *
  * If more than one sentinel server parameters are provided, the first
  * sentinel that connects will be used for retrival of information.
  *
  * @param mixed $connection_params
  */
 public function __construct($connection_params = null)
 {
     foreach ($connection_params as $connection) {
         $this->client = new Client($connection);
         // Usable connection is found
         if ($this->client->isConnected()) {
             break;
         }
     }
 }
 /**
  * @return bool
  */
 public function checkConnection()
 {
     if (!$this->predis->isConnected()) {
         try {
             $this->predis->connect();
             return true;
         } catch (ConnectionException $e) {
             return false;
         }
     }
     return true;
 }
Example #4
0
 /**
  * This method cannot be overridden because you need to override \Hoard\AbstractPool::getAdapterOptions().
  * @return \Predis\Client
  */
 protected final function getConnection()
 {
     // set the servers to use with this connection
     $servers = array();
     if (array_key_exists('servers', $this->adapterOptions)) {
         $servers = $this->adapterOptions['servers'];
     }
     // first time connect
     if (null == $this->connection || !$this->connection->isConnected()) {
         $this->connection = new PredisClient($servers);
     }
     return $this->connection;
 }
Example #5
0
 /**
  * @group disconnected
  */
 public function testIsConnectedChecksConnectionState()
 {
     $connection = $this->getMock('Predis\\Connection\\ConnectionInterface');
     $connection->expects($this->once())->method('isConnected');
     $client = new Client($connection);
     $client->isConnected();
 }
Example #6
0
 /**
  * @inheritdoc
  */
 public function isConnected()
 {
     return isset($this->client) && $this->client->isConnected();
 }