From d0572b0efc88aefe32e8fe13d3eefe47ff0ad13e Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Sun, 29 Jul 2012 11:48:04 +0200 Subject: [PATCH] Rename command hash strategy cass used by Predis cluster. --- ...tegy.php => PredisClusterHashStrategy.php} | 21 ++++++++-------- lib/Predis/Connection/PredisCluster.php | 5 ++-- ....php => PredisClusterHashStrategyTest.php} | 24 +++++++++---------- tests/Predis/Connection/PredisClusterTest.php | 2 +- 4 files changed, 26 insertions(+), 26 deletions(-) rename lib/Predis/Command/Hash/{CommandHashStrategy.php => PredisClusterHashStrategy.php} (93%) rename tests/Predis/Command/Hash/{CommandHashStrategyTest.php => PredisClusterHashStrategyTest.php} (94%) diff --git a/lib/Predis/Command/Hash/CommandHashStrategy.php b/lib/Predis/Command/Hash/PredisClusterHashStrategy.php similarity index 93% rename from lib/Predis/Command/Hash/CommandHashStrategy.php rename to lib/Predis/Command/Hash/PredisClusterHashStrategy.php index 8c0b457c..8eda02c0 100644 --- a/lib/Predis/Command/Hash/CommandHashStrategy.php +++ b/lib/Predis/Command/Hash/PredisClusterHashStrategy.php @@ -20,7 +20,7 @@ use Predis\Distribution\HashGeneratorInterface; * * @author Daniele Alessandri */ -class CommandHashStrategy implements CommandHashStrategyInterface +class PredisClusterHashStrategy implements CommandHashStrategyInterface { private $commands; @@ -40,11 +40,12 @@ class CommandHashStrategy implements CommandHashStrategyInterface protected function getDefaultCommands() { $keyIsFirstArgument = array($this, 'getKeyFromFirstArgument'); + $keysAreAllArguments = array($this, 'getKeyFromAllArguments'); return array( /* commands operating on the key space */ 'EXISTS' => $keyIsFirstArgument, - 'DEL' => array($this, 'getKeyFromAllArguments'), + 'DEL' => $keysAreAllArguments, 'TYPE' => $keyIsFirstArgument, 'EXPIRE' => $keyIsFirstArgument, 'EXPIREAT' => $keyIsFirstArgument, @@ -61,7 +62,7 @@ class CommandHashStrategy implements CommandHashStrategyInterface 'DECRBY' => $keyIsFirstArgument, 'GET' => $keyIsFirstArgument, 'GETBIT' => $keyIsFirstArgument, - 'MGET' => array($this, 'getKeyFromAllArguments'), + 'MGET' => $keysAreAllArguments, 'SET' => $keyIsFirstArgument, 'GETRANGE' => $keyIsFirstArgument, 'GETSET' => $keyIsFirstArgument, @@ -84,7 +85,7 @@ class CommandHashStrategy implements CommandHashStrategyInterface 'LLEN' => $keyIsFirstArgument, 'LPOP' => $keyIsFirstArgument, 'RPOP' => $keyIsFirstArgument, - 'RPOPLPUSH' => array($this, 'getKeyFromAllArguments'), + 'RPOPLPUSH' => $keysAreAllArguments, 'BLPOP' => array($this, 'getKeyFromBlockingListCommands'), 'BRPOP' => array($this, 'getKeyFromBlockingListCommands'), 'BRPOPLPUSH' => array($this, 'getKeyFromBlockingListCommands'), @@ -100,12 +101,12 @@ class CommandHashStrategy implements CommandHashStrategyInterface /* commands operating on sets */ 'SADD' => $keyIsFirstArgument, 'SCARD' => $keyIsFirstArgument, - 'SDIFF' => array($this, 'getKeyFromAllArguments'), - 'SDIFFSTORE' => array($this, 'getKeyFromAllArguments'), - 'SINTER' => array($this, 'getKeyFromAllArguments'), - 'SINTERSTORE' => array($this, 'getKeyFromAllArguments'), - 'SUNION' => array($this, 'getKeyFromAllArguments'), - 'SUNIONSTORE' => array($this, 'getKeyFromAllArguments'), + 'SDIFF' => $keysAreAllArguments, + 'SDIFFSTORE' => $keysAreAllArguments, + 'SINTER' => $keysAreAllArguments, + 'SINTERSTORE' => $keysAreAllArguments, + 'SUNION' => $keysAreAllArguments, + 'SUNIONSTORE' => $keysAreAllArguments, 'SISMEMBER' => $keyIsFirstArgument, 'SMEMBERS' => $keyIsFirstArgument, 'SPOP' => $keyIsFirstArgument, diff --git a/lib/Predis/Connection/PredisCluster.php b/lib/Predis/Connection/PredisCluster.php index 17f29440..05c3ab57 100644 --- a/lib/Predis/Connection/PredisCluster.php +++ b/lib/Predis/Connection/PredisCluster.php @@ -14,7 +14,7 @@ namespace Predis\Connection; use Predis\ClientException; use Predis\NotSupportedException; use Predis\Command\CommandInterface; -use Predis\Command\Hash\CommandHashStrategy; +use Predis\Command\Hash\PredisClusterHashStrategy; use Predis\Distribution\HashRing; use Predis\Distribution\DistributionStrategyInterface; @@ -37,7 +37,7 @@ class PredisCluster implements ClusterConnectionInterface, \IteratorAggregate, \ public function __construct(DistributionStrategyInterface $distributor = null) { $this->pool = array(); - $this->cmdHasher = new CommandHashStrategy(); + $this->cmdHasher = new PredisClusterHashStrategy(); $this->distributor = $distributor ?: new HashRing(); } @@ -151,7 +151,6 @@ class PredisCluster implements ClusterConnectionInterface, \IteratorAggregate, \ return isset($this->pool[$alias]) ? $this->pool[$alias] : null; } - /** * Retrieves a connection instance from the cluster using a key. * diff --git a/tests/Predis/Command/Hash/CommandHashStrategyTest.php b/tests/Predis/Command/Hash/PredisClusterHashStrategyTest.php similarity index 94% rename from tests/Predis/Command/Hash/CommandHashStrategyTest.php rename to tests/Predis/Command/Hash/PredisClusterHashStrategyTest.php index 6b61e9bd..34b34088 100644 --- a/tests/Predis/Command/Hash/CommandHashStrategyTest.php +++ b/tests/Predis/Command/Hash/PredisClusterHashStrategyTest.php @@ -19,7 +19,7 @@ use Predis\Profile\ServerProfile; /** * */ -class CommandHashStrategyTest extends StandardTestCase +class PredisClusterHashStrategyTest extends StandardTestCase { /** * @group disconnected @@ -28,7 +28,7 @@ class CommandHashStrategyTest extends StandardTestCase { $expected = -1938594527; $distribution = new HashRing(); - $hashstrategy = new CommandHashStrategy(); + $hashstrategy = new PredisClusterHashStrategy(); $this->assertSame($expected, $hashstrategy->getKeyHash($distribution, '{foo}')); $this->assertSame($expected, $hashstrategy->getKeyHash($distribution, '{foo}:bar')); @@ -44,7 +44,7 @@ class CommandHashStrategyTest extends StandardTestCase */ public function testSupportedCommands() { - $hashstrategy = new CommandHashStrategy(); + $hashstrategy = new PredisClusterHashStrategy(); $this->assertSame($this->getExpectedCommands(), $hashstrategy->getSupportedCommands()); } @@ -55,7 +55,7 @@ class CommandHashStrategyTest extends StandardTestCase public function testReturnsNullOnUnsupportedCommand() { $distribution = new HashRing(); - $hashstrategy = new CommandHashStrategy(); + $hashstrategy = new PredisClusterHashStrategy(); $command = ServerProfile::getDevelopment()->createCommand('ping'); $this->assertNull($hashstrategy->getHash($distribution, $command)); @@ -67,7 +67,7 @@ class CommandHashStrategyTest extends StandardTestCase public function testFirstKeyCommands() { $distribution = new HashRing(); - $hashstrategy = new CommandHashStrategy(); + $hashstrategy = new PredisClusterHashStrategy(); $profile = ServerProfile::getDevelopment(); $arguments = array('key'); @@ -83,7 +83,7 @@ class CommandHashStrategyTest extends StandardTestCase public function testAllKeysCommands() { $distribution = new HashRing(); - $hashstrategy = new CommandHashStrategy(); + $hashstrategy = new PredisClusterHashStrategy(); $profile = ServerProfile::getDevelopment(); $arguments = array('{key}:1', '{key}:2', '{key}:3', '{key}:4'); @@ -99,7 +99,7 @@ class CommandHashStrategyTest extends StandardTestCase public function testInterleavedKeysCommands() { $distribution = new HashRing(); - $hashstrategy = new CommandHashStrategy(); + $hashstrategy = new PredisClusterHashStrategy(); $profile = ServerProfile::getDevelopment(); $arguments = array('{key}:1', 'value1', '{key}:2', 'value2'); @@ -115,7 +115,7 @@ class CommandHashStrategyTest extends StandardTestCase public function testKeysForBlockingListCommands() { $distribution = new HashRing(); - $hashstrategy = new CommandHashStrategy(); + $hashstrategy = new PredisClusterHashStrategy(); $profile = ServerProfile::getDevelopment(); $arguments = array('{key}:1', '{key}:2', 10); @@ -131,7 +131,7 @@ class CommandHashStrategyTest extends StandardTestCase public function testKeysForZsetAggregationCommands() { $distribution = new HashRing(); - $hashstrategy = new CommandHashStrategy(); + $hashstrategy = new PredisClusterHashStrategy(); $profile = ServerProfile::getDevelopment(); $arguments = array('{key}:destination', 2, '{key}:1', '{key}:1', array('aggregate' => 'SUM')); @@ -147,7 +147,7 @@ class CommandHashStrategyTest extends StandardTestCase public function testKeysForBitOpCommand() { $distribution = new HashRing(); - $hashstrategy = new CommandHashStrategy(); + $hashstrategy = new PredisClusterHashStrategy(); $profile = ServerProfile::getDevelopment(); $arguments = array('AND', '{key}:destination', '{key}:src:1', '{key}:src:2'); @@ -163,7 +163,7 @@ class CommandHashStrategyTest extends StandardTestCase public function testUnsettingCommandHandler() { $distribution = new HashRing(); - $hashstrategy = new CommandHashStrategy(); + $hashstrategy = new PredisClusterHashStrategy(); $profile = ServerProfile::getDevelopment(); $hashstrategy->setCommandHandler('set'); @@ -182,7 +182,7 @@ class CommandHashStrategyTest extends StandardTestCase public function testSettingCustomCommandHandler() { $distribution = new HashRing(); - $hashstrategy = new CommandHashStrategy(); + $hashstrategy = new PredisClusterHashStrategy(); $profile = ServerProfile::getDevelopment(); $callable = $this->getMock('stdClass', array('__invoke')); diff --git a/tests/Predis/Connection/PredisClusterTest.php b/tests/Predis/Connection/PredisClusterTest.php index 3ccfb071..498ae5d9 100644 --- a/tests/Predis/Connection/PredisClusterTest.php +++ b/tests/Predis/Connection/PredisClusterTest.php @@ -26,7 +26,7 @@ class PredisClusterTest extends StandardTestCase public function testExposesCommandHashStrategy() { $cluster = new PredisCluster(); - $this->assertInstanceOf('Predis\Command\Hash\CommandHashStrategy', $cluster->getCommandHashStrategy()); + $this->assertInstanceOf('Predis\Command\Hash\PredisClusterHashStrategy', $cluster->getCommandHashStrategy()); } /**