From 6b82b412fb795f5c85a2c6bf526ef32907e0560c Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Sat, 1 Jan 2011 11:28:55 +0100 Subject: [PATCH] Cannot use the 'retry' option for transactions without providing a function block. --- lib/Predis.php | 13 +++++++++++-- test/PredisClientFeatures.php | 10 ++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/Predis.php b/lib/Predis.php index 9be07469..0ef92f2e 100644 --- a/lib/Predis.php +++ b/lib/Predis.php @@ -882,16 +882,25 @@ class MultiExecBlock { return $this->execute(); } - public function execute($block = null) { + private function checkBeforeExecution($block) { if ($this->_insideBlock === true) { throw new 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(); diff --git a/test/PredisClientFeatures.php b/test/PredisClientFeatures.php index 665685a5..94f8ed55 100644 --- a/test/PredisClientFeatures.php +++ b/test/PredisClientFeatures.php @@ -735,6 +735,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();