Browse Source

Less code duplication please.

Daniele Alessandri 15 years ago
parent
commit
371a7ad69b
1 changed files with 11 additions and 11 deletions
  1. 11 11
      lib/Predis.php

+ 11 - 11
lib/Predis.php

@@ -783,21 +783,12 @@ class MultiExecBlock {
 
     private function checkCapabilities(Client $redisClient) {
         $profile = $redisClient->getProfile();
-
-        $canMulti = $profile->supportsCommand('multi') && 
-                    $profile->supportsCommand('exec') &&
-                    $profile->supportsCommand('discard');
-
-        $canWatch = $profile->supportsCommand('watch') && 
-                    $profile->supportsCommand('unwatch');
-
-        if ($canMulti === false) {
+        if ($profile->supportsCommands(array('multi', 'exec', 'discard')) === false) {
             throw new \Predis\ClientException(
                 'The current profile does not support MULTI, EXEC and DISCARD commands'
             );
         }
-
-        $this->_supportsWatch = $canWatch;
+        $this->_supportsWatch = $profile->supportsCommands(array('watch', 'unwatch'));
     }
 
     private function isWatchSupported() {
@@ -1461,6 +1452,15 @@ abstract class RedisServerProfile {
         return new $profile();
     }
 
+    public function supportsCommands(Array $commands) {
+        foreach ($commands as $command) {
+            if ($this->supportsCommand($command) === false) {
+                return false;
+            }
+        }
+        return true;
+    }
+
     public function supportsCommand($command) {
         return isset($this->_registeredCommands[$command]);
     }