pSubscribe() public method

public pSubscribe ( string | array $patterns, $callback )
$patterns string | array
$callback
Esempio n. 1
0
 public function testPubsub()
 {
     $timeout = 2;
     $time = time();
     $this->credis->setReadTimeout($timeout);
     try {
         $testCase = $this;
         $this->credis->pSubscribe(array('foobar', 'test*'), function ($credis, $pattern, $channel, $message) use($testCase, &$time) {
             $time = time();
             // Reset timeout
             // Test using: redis-cli publish foobar blah
             $testCase->assertEquals('blah', $message);
         });
         $this->fail('pSubscribe should not return.');
     } catch (CredisException $e) {
         $this->assertEquals($timeout, time() - $time);
         if ($this->useStandalone) {
             // phpredis does not distinguish between timed out and disconnected
             $this->assertEquals($e->getCode(), CredisException::CODE_TIMED_OUT);
         } else {
             $this->assertEquals($e->getCode(), CredisException::CODE_DISCONNECTED);
         }
     }
     // Perform a new subscription. Client should have either unsubscribed or disconnected
     $timeout = 2;
     $time = time();
     $this->credis->setReadTimeout($timeout);
     try {
         $testCase = $this;
         $this->credis->subscribe('foobar', function ($credis, $channel, $message) use($testCase, &$time) {
             $time = time();
             // Reset timeout
             // Test using: redis-cli publish foobar blah
             $testCase->assertEquals('blah', $message);
         });
         $this->fail('subscribe should not return.');
     } catch (CredisException $e) {
         $this->assertEquals($timeout, time() - $time);
         if ($this->useStandalone) {
             // phpredis does not distinguish between timed out and disconnected
             $this->assertEquals($e->getCode(), CredisException::CODE_TIMED_OUT);
         } else {
             $this->assertEquals($e->getCode(), CredisException::CODE_DISCONNECTED);
         }
     }
 }