Преглед на файлове

Cannot use the 'retry' option for transactions without providing a function block.

Daniele Alessandri преди 14 години
родител
ревизия
87439ae631
променени са 2 файла, в които са добавени 21 реда и са изтрити 2 реда
  1. 11 2
      lib/Predis.php
  2. 10 0
      test/PredisClientFeatures.php

+ 11 - 2
lib/Predis.php

@@ -922,16 +922,25 @@ class MultiExecBlock {
         return $this->execute();
     }
 
-    public function execute($block = null) {
+    private function checkBeforeExecution($block) {
         if ($this->_insideBlock === true) {
             throw new \Predis\ClientException(
                 "Cannot invoke 'execute' or 'exec' inside an active client transaction block"
             );
         }
-
         if ($block && !is_callable($block)) {
             throw new \InvalidArgumentException('Argument passed must be a callable object');
         }
+        if (isset($this->_options['retry']) && !isset($block)) {
+            $this->discard();
+            throw new \InvalidArgumentException(
+                'Automatic retries can be used only when a transaction block is provided'
+            );
+        }
+    }
+
+    public function execute($block = null) {
+        $this->checkBeforeExecution($block);
 
         $reply = null;
         $returnValues = array();

+ 10 - 0
test/PredisClientFeatures.php

@@ -695,6 +695,16 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
         $this->assertEquals($attempts, $client1->get('attempts'));
     }
 
+    /**
+     * @expectedException InvalidArgumentException
+     */
+    function testMultiExecBlock_RetryNotAvailableWithoutBlock() {
+        $options = array('watch' => 'foo', 'retry' => 1);
+        $tx = RC::getConnection()->multiExec($options);
+        $tx->multi();
+        $tx->get('foo')->exec();
+    }
+
     function testMultiExecBlock_CheckAndSet_Discard() {
         $client = RC::getConnection();
         $client->flushdb();