Check for the capabilities of the passed client instance when initializing a \Predis\PubSubContext instance.

This commit is contained in:
Daniele Alessandri
2010-06-12 10:06:13 +02:00
parent 371a7ad69b
commit 35b8588dc4
+11
View File
@@ -943,6 +943,7 @@ class PubSubContext implements \Iterator {
private $_redisClient, $_subscriptions, $_isStillValid, $_position;
public function __construct(Client $redisClient) {
$this->checkCapabilities($redisClient);
$this->_redisClient = $redisClient;
$this->_isStillValid = true;
$this->_subscriptions = false;
@@ -955,6 +956,16 @@ class PubSubContext implements \Iterator {
}
}
private function checkCapabilities(Client $redisClient) {
$profile = $redisClient->getProfile();
$commands = array('publish', 'subscribe', 'unsubscribe', 'psubscribe', 'punsubscribe');
if ($profile->supportsCommands($commands) === false) {
throw new \Predis\ClientException(
'The current profile does not support PUB/SUB related commands'
);
}
}
public function subscribe(/* arguments */) {
$this->writeCommand(self::SUBSCRIBE, func_get_args());
$this->_subscriptions = true;