mirror of
https://github.com/predis/predis.git
synced 2026-08-30 20:21:31 +00:00
Check for the capabilities of the passed client instance when initializing a \Predis\PubSubContext instance.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user