diff --git a/examples/PubSubContext.php b/examples/PubSubContext.php index d08eac60..42428c37 100644 --- a/examples/PubSubContext.php +++ b/examples/PubSubContext.php @@ -18,7 +18,7 @@ require 'SharedConfigurations.php'; $client = new Predis\Client($single_server + array('read_write_timeout' => 0)); // Initialize a new pubsub context -$pubsub = $client->pubSub(); +$pubsub = $client->pubSubLoop(); // Subscribe to your channels $pubsub->subscribe('control_channel', 'notifications'); diff --git a/lib/Predis/Client.php b/lib/Predis/Client.php index 5303f432..6b4967ed 100644 --- a/lib/Predis/Client.php +++ b/lib/Predis/Client.php @@ -394,10 +394,27 @@ class Client implements ClientInterface * Creates a new Publish / Subscribe context and returns it, or executes it * inside the optionally provided callable object. * + * @deprecated This method will change in the next major release to support + * the new PUBSUB command introduced in Redis 2.8. Please use + * Client::pubSubLoop() to create Predis\PubSub\PubSubContext + * instances from now on. + * * @param mixed $arg,... Options for the context, a callable object, or both. - * @return MultiExecContext|array + * @return PubSubExecContext|array */ public function pubSub(/* arguments */) + { + return call_user_func_array(array($this, 'pubSubLoop'), func_get_args()); + } + + /** + * Creates a new Publish / Subscribe context and returns it, or executes it + * inside the optionally provided callable object. + * + * @param mixed $arg,... Options for the context, a callable object, or both. + * @return PubSubExecContext|array + */ + public function pubSubLoop(/* arguments */) { return $this->sharedInitializer(func_get_args(), 'initPubSub'); } diff --git a/lib/Predis/PubSub/DispatcherLoop.php b/lib/Predis/PubSub/DispatcherLoop.php index 32548972..0a16b195 100644 --- a/lib/Predis/PubSub/DispatcherLoop.php +++ b/lib/Predis/PubSub/DispatcherLoop.php @@ -33,7 +33,7 @@ class DispatcherLoop public function __construct(ClientInterface $client) { $this->callbacks = array(); - $this->pubSubContext = $client->pubSub(); + $this->pubSubContext = $client->pubSubLoop(); } /** diff --git a/tests/Predis/ClientTest.php b/tests/Predis/ClientTest.php index 5d3f16be..4bea320f 100644 --- a/tests/Predis/ClientTest.php +++ b/tests/Predis/ClientTest.php @@ -584,24 +584,24 @@ class ClientTest extends StandardTestCase /** * @group disconnected */ - public function testPubSubWithoutArgumentsReturnsPubSubContext() + public function testPubSubLoopWithoutArgumentsReturnsPubSubContext() { $client = new Client(); - $this->assertInstanceOf('Predis\PubSub\PubSubContext', $pubsub = $client->pubSub()); + $this->assertInstanceOf('Predis\PubSub\PubSubContext', $pubsub = $client->pubSubLoop()); } /** * @group disconnected */ - public function testPubSubWithArrayReturnsPubSubContextWithOptions() + public function testPubSubLoopWithArrayReturnsPubSubContextWithOptions() { $connection = $this->getMock('Predis\Connection\SingleConnectionInterface'); $options = array('subscribe' => 'channel'); $client = new Client($connection); - $this->assertInstanceOf('Predis\PubSub\PubSubContext', $pubsub = $client->pubSub($options)); + $this->assertInstanceOf('Predis\PubSub\PubSubContext', $pubsub = $client->pubSubLoop($options)); $reflection = new \ReflectionProperty($pubsub, 'options'); $reflection->setAccessible(true); @@ -612,7 +612,7 @@ class ClientTest extends StandardTestCase /** * @group disconnected */ - public function testPubSubWithArrayAndCallableExecutesPubSub() + public function testPubSubLoopWithArrayAndCallableExecutesPubSub() { // NOTE: we use a subscribe count of 0 in the fake message to trick // the context and to make it think that it can be closed @@ -631,7 +631,17 @@ class ClientTest extends StandardTestCase ->method('__invoke'); $client = new Client($connection); - $client->pubSub($options, $callable); + $client->pubSubLoop($options, $callable); + } + + /** + * @group disconnected + */ + public function testPubSubIsAliasForPubSubLoop() + { + $client = new Client(); + + $this->assertInstanceOf('Predis\PubSub\PubSubContext', $client->pubSub()); } /**