disconnect() public method

Closes the underlying connection and disconnects from the server.
public disconnect ( )
Example #1
1
 /**
  * Flush all keys in Redis
  */
 public function clear_redis_cache()
 {
     $redis_host = config('database.redis.default.host');
     $redis_port = config('database.redis.default.port');
     $this->info('Clearing the Redis Cache at: ' . $redis_host . ':' . $redis_port);
     try {
         $redis = new Client(['host' => $redis_host, 'port' => $redis_port]);
         $redis->flushall();
         $redis->disconnect();
     } catch (Exception $e) {
         $this->error('Failed to clear the Redis Cache. Error: ' . $e->getMessage());
     }
     return;
 }
Example #2
0
 /**
  * @inheritdoc
  */
 public function disconnect()
 {
     if (!$this->isConnected()) {
         return;
     }
     $this->client->disconnect();
     $this->client = null;
 }
 public function fork()
 {
     $id = pcntl_fork();
     if (!$id) {
         $this->redis->disconnect();
         $this->redis->connect();
     }
     return $id;
 }
Example #4
0
 /**
  * Properly close the connection.
  *
  * {@inheritdoc}
  */
 public function __destruct()
 {
     if ($this->redis instanceof \Predis\Client) {
         try {
             $this->redis->disconnect();
         } catch (\ConnectionException $e) {
             /*
              * \Predis\Client::disconnect will throw a \ConnectionException("Redis server went away") exception if
              * we haven't previously been able to connect to Redis or the connection has severed.
              */
         }
     }
 }
Example #5
0
 public function Cleanup()
 {
     $this->status = 'offline';
     $this->Report();
     $this->redis->disconnect();
     unset($this->beanstalk);
     unset($this->redis);
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     $client = new Client();
     try {
         $client->connect();
         $client->disconnect();
         self::$supported = true;
     } catch (ConnectionException $e) {
         self::$supported = false;
     }
 }
Example #7
0
 /**
  * @group disconnected
  */
 public function testConnectAndDisconnect()
 {
     $connection = $this->getMock('Predis\\Connection\\ConnectionInterface');
     $connection->expects($this->once())->method('connect');
     $connection->expects($this->once())->method('disconnect');
     $client = new Client($connection);
     $client->connect();
     $client->disconnect();
 }
Example #8
0
 public function __destruct()
 {
     $this->predis->disconnect();
 }
 /**
  * @group connected
  * @requires extension pcntl
  */
 public function testPubSubAgainstRedisServerBlocking()
 {
     $parameters = array('host' => REDIS_SERVER_HOST, 'port' => REDIS_SERVER_PORT, 'database' => REDIS_SERVER_DBNUM, 'read_write_timeout' => -1);
     $options = array('profile' => REDIS_SERVER_VERSION);
     // create consumer before forking so the child can disconnect it
     $consumer = new Client($parameters, $options);
     $consumer->connect();
     /*
      * fork
      *  parent: consumer
      *  child: producer
      */
     if ($childPID = pcntl_fork()) {
         $messages = array();
         $pubsub = new PubSubConsumer($consumer);
         $pubsub->subscribe('channel:foo');
         foreach ($pubsub as $message) {
             if ($message->kind !== 'message') {
                 continue;
             }
             $messages[] = $payload = $message->payload;
             if ($payload === 'QUIT') {
                 $pubsub->stop();
             }
         }
         $this->assertSame(array('message1', 'message2', 'QUIT'), $messages);
         $this->assertFalse($pubsub->valid());
         $this->assertEquals('ECHO', $consumer->echo('ECHO'));
         // kill the child
         posix_kill($childPID, SIGKILL);
     } else {
         // create producer, read_write_timeout = 2 because it doesn't do blocking reads anyway
         $producer = new Client(array_replace($parameters, array('read_write_timeout' => 2)), $options);
         $producer->connect();
         $producer->publish('channel:foo', 'message1');
         $producer->publish('channel:foo', 'message2');
         $producer->publish('channel:foo', 'QUIT');
         // sleep, giving the consumer a chance to respond to the QUIT message
         sleep(1);
         // disconnect the consumer because otherwise it could remain stuck in blocking read
         //  if it failed to respond to the QUIT message
         $consumer->disconnect();
         // exit child
         exit(0);
     }
 }
Example #10
0
 public function disconnect()
 {
     $this->_client->disconnect();
 }
Example #11
0
 public function __destruct()
 {
     $this->client->disconnect();
 }