Bläddra i källkod

Rename RedisCluster::askClusterNodes() to askSlotsMap().

This is more consistent with the actual purpose of this method and
more in-line with a possible future change in the underlying command
used to retrieve the slots map if redis-cluster will implement the
CLUSTER SLOTS command.
Daniele Alessandri 11 år sedan
förälder
incheckning
e575c32cb4

+ 11 - 7
lib/Predis/Connection/Aggregate/RedisCluster.php

@@ -48,7 +48,7 @@ use Predis\Response\ErrorInterface as ErrorResponseInterface;
  */
 class RedisCluster implements ClusterInterface, IteratorAggregate, Countable
 {
-    private $askClusterNodes = false;
+    private $askSlotsMap = false;
     private $defaultParameters = array();
     private $pool = array();
     private $slots = array();
@@ -173,8 +173,10 @@ class RedisCluster implements ClusterInterface, IteratorAggregate, Countable
     /**
      * Generates the current slots map by fetching the cluster configuration to
      * one of the nodes by leveraging the CLUSTER NODES command.
+     *
+     * @return array
      */
-    public function askClusterNodes()
+    public function askSlotsMap()
     {
         if (!$connection = $this->getRandomConnection()) {
             return array();
@@ -201,6 +203,8 @@ class RedisCluster implements ClusterInterface, IteratorAggregate, Countable
                 $this->setSlots($slots[0], $slots[1], $node[1]);
             }
         }
+
+        return $this->slotsMap;
     }
 
     /**
@@ -406,8 +410,8 @@ class RedisCluster implements ClusterInterface, IteratorAggregate, Countable
             $connection = $this->createConnection($connectionID);
         }
 
-        if ($this->askClusterNodes) {
-            $this->askClusterNodes();
+        if ($this->askSlotsMap) {
+            $this->askSlotsMap();
         }
 
         $this->move($connection, $slot);
@@ -504,14 +508,14 @@ class RedisCluster implements ClusterInterface, IteratorAggregate, Countable
      * procedure, mostly when targeting many keys that would end up in a lot of
      * redirections.
      *
-     * The slots map can still be manually fetched using the askClusterNodes()
+     * The slots map can still be manually fetched using the askSlotsMap()
      * method whether or not this option is enabled.
      *
      * @param bool $value Enable or disable the use of CLUSTER NODES.
      */
-    public function enableClusterNodes($value)
+    public function enableAutoSlotsMap($value)
     {
-        $this->askClusterNodes = (bool) $value;
+        $this->askSlotsMap = (bool) $value;
     }
 
     /**

+ 1 - 1
tests/Predis/Connection/Aggregate/RedisClusterTest.php

@@ -655,7 +655,7 @@ EOS;
         $cluster = new RedisCluster($factory);
         $cluster->add($connection1);
 
-        $cluster->askClusterNodes();
+        $cluster->askSlotsMap();
 
         $this->assertSame($cluster->getConnectionBySlot('6144'), $connection1);
     }