Forráskód Böngészése

Handle error responses returned by redis-sentinel.

Fixes #289.
Daniele Alessandri 9 éve
szülő
commit
be8ac3e205
1 módosított fájl, 17 hozzáadás és 2 törlés
  1. 17 2
      src/Connection/Aggregate/SentinelReplication.php

+ 17 - 2
src/Connection/Aggregate/SentinelReplication.php

@@ -317,6 +317,21 @@ class SentinelReplication implements ReplicationInterface
         $this->getSlaves();
     }
 
+    /**
+     * Handles error responses returned by redis-sentinel.
+     *
+     * @param NodeConnectionInterface $sentinel Connection to a sentinel server.
+     * @param ErrorResponseInterface  $error    Error response.
+     */
+    private function handleSentinelErrorResponse(NodeConnectionInterface $sentinel, ErrorResponseInterface $error)
+    {
+        if ($error->getErrorType() === 'IDONTKNOW') {
+            throw new ConnectionException($sentinel, $error->getMessage());
+        } else {
+            throw new ServerException($error->getMessage());
+        }
+    }
+
     /**
      * Fetches the details for the master server from a sentinel.
      *
@@ -336,7 +351,7 @@ class SentinelReplication implements ReplicationInterface
         }
 
         if ($payload instanceof ErrorResponseInterface) {
-            throw new ServerException($payload->getMessage());
+            $this->handleSentinelErrorResponse($sentinel, $payload);
         }
 
         return array(
@@ -363,7 +378,7 @@ class SentinelReplication implements ReplicationInterface
         );
 
         if ($payload instanceof ErrorResponseInterface) {
-            throw new ServerException($payload->getMessage());
+            $this->handleSentinelErrorResponse($sentinel, $payload);
         }
 
         foreach ($payload as $slave) {