Forráskód Böngészése

Support DISCARD with CAS.

Daniele Alessandri 14 éve
szülő
commit
34f4d5584b
2 módosított fájl, 22 hozzáadás és 1 törlés
  1. 4 1
      lib/Predis.php
  2. 18 0
      test/PredisClientFeatures.php

+ 4 - 1
lib/Predis.php

@@ -850,8 +850,11 @@ class MultiExecBlock {
             if (isset($options['watch'])) {
                 $this->watch($options['watch']);
             }
-            if (!$this->_checkAndSet) {
+            if (!$this->_checkAndSet || ($this->_discarded && $this->_checkAndSet)) {
                 $this->_redisClient->multi();
+                if ($this->_discarded) {
+                    $this->_checkAndSet = false;
+                }
             }
             $this->_initialized = true;
             $this->_discarded   = false;

+ 18 - 0
test/PredisClientFeatures.php

@@ -636,5 +636,23 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
         $this->assertType('array', $replies);
         $this->assertEquals(array(true, array('bar', 'bar')), $replies);
     }
+
+    function testMultiExecBlock_CheckAndSet_Discard() {
+        $client = RC::getConnection();
+        $client->flushdb();
+        $client->set('foo', 'bar');
+
+        $options = array('watch' => 'foo', 'cas' => true);
+        $replies = $client->multiExec($options, function($tx) {
+            $tx->watch('foobar');
+            $foo = $tx->get('foo');
+            $tx->multi();
+            $tx->set('foobar', $foo);
+            $tx->discard();
+            $tx->mget('foo', 'foobar');
+        });
+        $this->assertType('array', $replies);
+        $this->assertEquals(array(array('bar', null)), $replies);
+    }
 }
 ?>