Support DISCARD with CAS.

This commit is contained in:
Daniele Alessandri
2010-12-31 15:28:02 +01:00
parent 39619d0c54
commit 34f4d5584b
2 changed files with 22 additions and 1 deletions
+4 -1
View File
@@ -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
View File
@@ -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);
}
}
?>