diff --git a/src/Connection/Aggregate/RedisCluster.php b/src/Connection/Aggregate/RedisCluster.php index d12d651e..47885a6e 100644 --- a/src/Connection/Aggregate/RedisCluster.php +++ b/src/Connection/Aggregate/RedisCluster.php @@ -16,6 +16,7 @@ use Countable; use IteratorAggregate; use OutOfBoundsException; use Predis\NotSupportedException; +use Predis\Cluster\StrategyInterface; use Predis\Cluster\RedisStrategy as RedisClusterStrategy; use Predis\Command\CommandInterface; use Predis\Command\RawCommand; @@ -57,12 +58,15 @@ class RedisCluster implements ClusterInterface, IteratorAggregate, Countable private $connections; /** - * @param FactoryInterface $connections Connection factory object. + * @param FactoryInterface $connections Connection factory instance. + * @param StrategyInterface $strategy Cluster strategy instance. */ - public function __construct(FactoryInterface $connections = null) - { - $this->strategy = new RedisClusterStrategy(); + public function __construct( + FactoryInterface $connections = null, + StrategyInterface $strategy = null + ) { $this->connections = $connections ?: new Factory(); + $this->strategy = $strategy ?: new RedisClusterStrategy(); } /** @@ -486,7 +490,7 @@ class RedisCluster implements ClusterInterface, IteratorAggregate, Countable * Returns the underlying command hash strategy used to hash commands by * using keys found in their arguments. * - * @return \Predis\Cluster\StrategyInterface + * @return StrategyInterface */ public function getClusterStrategy() { diff --git a/tests/Predis/Connection/Aggregate/RedisClusterTest.php b/tests/Predis/Connection/Aggregate/RedisClusterTest.php index a3f471bf..d10720b7 100644 --- a/tests/Predis/Connection/Aggregate/RedisClusterTest.php +++ b/tests/Predis/Connection/Aggregate/RedisClusterTest.php @@ -25,12 +25,24 @@ class RedisClusterTest extends PredisTestCase /** * @group disconnected */ - public function testExposesCommandHashStrategy() + public function testUsesRedisClusterStrategyByDefault() { $cluster = new RedisCluster(); + $this->assertInstanceOf('Predis\Cluster\RedisStrategy', $cluster->getClusterStrategy()); } + /** + * @group disconnected + */ + public function testAcceptsCustomClusterStrategy() + { + $strategy = $this->getMock('Predis\Cluster\StrategyInterface'); + $cluster = new RedisCluster(null, $strategy); + + $this->assertSame($strategy, $cluster->getClusterStrategy()); + } + /** * @group disconnected */