Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UPD] Added retries if exception is BUSY #190

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1226,9 +1226,26 @@ public function __call($name, $args)
throw $e;
}
} else {
$this->write_command($command);
$response = $this->read_reply($name);
$response = $this->decode_reply($name, $response, $trackedArgs);
$retryCount = 0;
$maxRetries = 5;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A hard-coded retry count really isn't appropriate, this should be linked to a configurable and probably with a lower limit or disabled by default.


while ($retryCount < $maxRetries) {
try {
$this->write_command($command);
$response = $this->read_reply($name);
$response = $this->decode_reply($name, $response, $trackedArgs);
break; // Exit loop if successful
} catch (CredisException $e) {
if (strpos($e->getMessage(), 'BUSY') === 0) {
$retryCount++;
if ($retryCount >= $maxRetries) {
throw $e; // Rethrow exception after max retries
}
} else {
throw $e; // Rethrow exception if message does not contain 'BUSY'
}
}
}
}

// Watch mode disables reconnect so error is thrown
Expand Down