Move the code that executes a transaction block to a separate method.

This commit is contained in:
Daniele Alessandri
2011-08-21 15:15:39 +02:00
parent 0bdcf299c2
commit d01e738d59
+23 -19
View File
@@ -190,26 +190,8 @@ class MultiExecContext {
$attemptsLeft = isset($this->_options['retry']) ? (int)$this->_options['retry'] : 0;
do {
$blockException = null;
if ($block !== null) {
$this->flagState(self::STATE_INSIDEBLOCK);
try {
$block($this);
}
catch (CommunicationException $exception) {
$blockException = $exception;
}
catch (ServerException $exception) {
$blockException = $exception;
}
catch (\Exception $exception) {
$blockException = $exception;
$this->discard();
}
$this->unflagState(self::STATE_INSIDEBLOCK);
if ($blockException !== null) {
throw $blockException;
}
$this->executeTransactionBlock($block);
}
if (count($this->_commands) === 0) {
@@ -252,6 +234,28 @@ class MultiExecContext {
return $returnValues;
}
private function executeTransactionBlock($block) {
$blockException = null;
$this->flagState(self::STATE_INSIDEBLOCK);
try {
$block($this);
}
catch (CommunicationException $exception) {
$blockException = $exception;
}
catch (ServerException $exception) {
$blockException = $exception;
}
catch (\Exception $exception) {
$blockException = $exception;
$this->discard();
}
$this->unflagState(self::STATE_INSIDEBLOCK);
if ($blockException !== null) {
throw $blockException;
}
}
private function onProtocolError($message) {
// Since a MULTI/EXEC block cannot be initialized over a clustered
// connection, we can safely assume that Predis\Client::getConnection()