mirror of
https://github.com/predis/predis.git
synced 2026-08-30 20:21:31 +00:00
Move the code that executes a transaction block to a separate method.
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user