mirror of
https://github.com/predis/predis.git
synced 2026-10-28 22:57:54 +00:00
Added retry support (#1616)
* Initial work on retries * Added retry class and test coverage * Added support for standalone and cluster * Make TimeoutException instance of CommunicationException * Added pipeline, trasnaction, replication support * Fixed broken test * Marked test as relay-incompatible * Marked test as relay-incompatible * Fixed analysis errors, added missing tests * Codestyle fixes * Fixed test * Update README.md * Update README.md * Update README.md * Updated README.md * Refactor retry on read and write * Added check for timeout value * Updated README.md * Fixed README.md * Codestyle changes * Added missing coverage * Added missing test coverage * Removed comments * Added retry support for Relay connection (#1620) * Added integration test case with mocked retry * Changed client initialisation in tests * Marked test as relay-incompatible --------- Co-authored-by: Pavlo Yatsukhnenko <yatsukhnenko@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
0ae180c942
commit
980326d5d8
+16
-1
@@ -22,6 +22,7 @@ use Predis\Command\RawCommand;
|
||||
use Predis\Command\ScriptCommand;
|
||||
use Predis\Configuration\Options;
|
||||
use Predis\Configuration\OptionsInterface;
|
||||
use Predis\Connection\AggregateConnectionInterface;
|
||||
use Predis\Connection\ConnectionInterface;
|
||||
use Predis\Connection\Parameters;
|
||||
use Predis\Connection\ParametersInterface;
|
||||
@@ -41,6 +42,7 @@ use Predis\Response\ServerException;
|
||||
use Predis\Transaction\MultiExec as MultiExecTransaction;
|
||||
use ReturnTypeWillChange;
|
||||
use RuntimeException;
|
||||
use Throwable;
|
||||
use Traversable;
|
||||
|
||||
/**
|
||||
@@ -376,12 +378,25 @@ class Client implements ClientInterface, IteratorAggregate
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function executeCommand(CommandInterface $command)
|
||||
{
|
||||
$response = $this->connection->executeCommand($command);
|
||||
$parameters = $this->connection->getParameters();
|
||||
|
||||
if ($this->connection instanceof AggregateConnectionInterface || $this->connection instanceof RelayConnection) {
|
||||
$response = $this->connection->executeCommand($command);
|
||||
} else {
|
||||
$response = $parameters->retry->callWithRetry(
|
||||
function () use ($command) {
|
||||
return $this->connection->executeCommand($command);
|
||||
},
|
||||
function () {
|
||||
$this->connection->disconnect();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if ($response instanceof ResponseInterface) {
|
||||
if ($response instanceof ErrorResponseInterface) {
|
||||
$response = $this->onErrorResponse($command, $response);
|
||||
|
||||
Reference in New Issue
Block a user