Fix improper handling of a few corner cases for Predis\MultiExecBlock and send DISCARD to the server on uncaught exceptions inside a callable block.

This commit is contained in:
Daniele Alessandri
2010-09-25 15:06:03 +02:00
parent fea5e1c602
commit 9ac4571f91
+38 -31
View File
@@ -923,45 +923,52 @@ class MultiExecBlock {
$blockException = null;
$returnValues = array();
try {
if ($block !== null) {
$this->setInsideBlock(true);
if ($block !== null) {
$this->setInsideBlock(true);
try {
$block($this);
$this->setInsideBlock(false);
}
if ($this->_discarded === true) {
return;
catch (CommunicationException $exception) {
$blockException = $exception;
}
$reply = $this->_redisClient->exec();
if ($reply === null) {
throw new AbortedMultiExec('The current transaction has been aborted by the server');
catch (ServerException $exception) {
$blockException = $exception;
}
$execReply = $reply instanceof \Iterator ? iterator_to_array($reply) : $reply;
$commands = &$this->_commands;
$sizeofReplies = count($execReply);
if ($sizeofReplies !== count($commands)) {
$this->malformedServerResponse('Unexpected number of responses for a MultiExecBlock');
catch (\Exception $exception) {
$blockException = $exception;
if ($this->_initialized === true) {
$this->discard();
}
}
for ($i = 0; $i < $sizeofReplies; $i++) {
$returnValues[] = $commands[$i]->parseResponse($execReply[$i] instanceof \Iterator
? iterator_to_array($execReply[$i])
: $execReply[$i]
);
unset($commands[$i]);
}
}
catch (\Exception $exception) {
$this->setInsideBlock(false);
$blockException = $exception;
if ($blockException !== null) {
throw $blockException;
}
}
if ($blockException !== null) {
throw $blockException;
if ($this->_initialized === false) {
return;
}
$reply = $this->_redisClient->exec();
if ($reply === null) {
throw new AbortedMultiExec('The current transaction has been aborted by the server');
}
$execReply = $reply instanceof \Iterator ? iterator_to_array($reply) : $reply;
$commands = &$this->_commands;
$sizeofReplies = count($execReply);
if ($sizeofReplies !== count($commands)) {
$this->malformedServerResponse('Unexpected number of responses for a MultiExecBlock');
}
for ($i = 0; $i < $sizeofReplies; $i++) {
$returnValues[] = $commands[$i]->parseResponse($execReply[$i] instanceof \Iterator
? iterator_to_array($execReply[$i])
: $execReply[$i]
);
unset($commands[$i]);
}
return $returnValues;