mirror of
https://github.com/predis/predis.git
synced 2026-09-15 12:57:10 +00:00
Make it possible to specify a custom strategy for redis-cluster.
This commit is contained in:
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user