Преглед на файлове

Merge remote-tracking branch 'github/pr/306' into v1.1-sentinel

Daniele Alessandri преди 9 години
родител
ревизия
e896d89fa8
променени са 1 файла, в които са добавени 10 реда и са изтрити 7 реда
  1. 10 7
      src/Connection/Aggregate/SentinelReplication.php

+ 10 - 7
src/Connection/Aggregate/SentinelReplication.php

@@ -56,9 +56,9 @@ class SentinelReplication extends MasterSlaveReplication
     protected $sentinelTimeout = 0.100;
 
     /**
-     * Flag for automatic retries of commands upon server failure.
+     * Max number of automatic retries of commands upon server failure. 0 = never retry, -1 = unlimited.
      */
-    protected $autoRetry = true;
+    protected $retryLimit = -1;
 
     /**
      * Flag for automatic fetching of available sentinels.
@@ -98,13 +98,13 @@ class SentinelReplication extends MasterSlaveReplication
     }
 
     /**
-     * Set automatic retries of commands upon server failure.
+     * Set maximum number of automatic retries of commands upon server failure. 0 = never retry, -1 = unlimited.
      *
-     * @param bool $retry Retry value.
+     * @param integer $retry Retry value.
      */
-    public function setAutomaticRetry($retry)
+    public function setRetryLimit($retry)
     {
-        $this->autoRetry = (bool) $retry;
+        $this->retryLimit = (int) $retry;
     }
 
     /**
@@ -323,17 +323,20 @@ class SentinelReplication extends MasterSlaveReplication
      */
     private function retryCommandOnFailure($method, $command)
     {
+        $retries = 0;
+
         SENTINEL_RETRY: {
             try {
                 $response = parent::$method($command);
             } catch (ConnectionException $exception) {
-                if (!$this->autoRetry) {
+                if ($retries == $this->retryLimit) {
                     throw $exception;
                 }
 
                 $exception->getConnection()->disconnect();
                 $this->querySentinel();
 
+                $retries++;
                 goto SENTINEL_RETRY;
             }
         }