Quellcode durchsuchen

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

Daniele Alessandri vor 15 Jahren
Ursprung
Commit
35b8588dc4
1 geänderte Dateien mit 11 neuen und 0 gelöschten Zeilen
  1. 11 0
      lib/Predis.php

+ 11 - 0
lib/Predis.php

@@ -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;