mirror of
https://github.com/predis/predis.git
synced 2026-08-30 20:21:31 +00:00
Move IDistributionAlgorithm, HashRing and KetamaPureRing to the new Predis\Distribution namespace.
This commit is contained in:
+29
-25
@@ -243,12 +243,12 @@ class ClientOptionsProfile implements IClientOptionsHandler {
|
||||
|
||||
class ClientOptionsKeyDistribution implements IClientOptionsHandler {
|
||||
public function validate($option, $value) {
|
||||
if ($value instanceof \Predis\IDistributionAlgorithm) {
|
||||
if ($value instanceof \Predis\Distribution\IDistributionAlgorithm) {
|
||||
return $value;
|
||||
}
|
||||
if (is_string($value)) {
|
||||
$valueReflection = new \ReflectionClass($value);
|
||||
if ($valueReflection->isSubclassOf('\Predis\IDistributionAlgorithm')) {
|
||||
if ($valueReflection->isSubclassOf('\Predis\Distribution\IDistributionAlgorithm')) {
|
||||
return new $value;
|
||||
}
|
||||
}
|
||||
@@ -256,7 +256,7 @@ class ClientOptionsKeyDistribution implements IClientOptionsHandler {
|
||||
}
|
||||
|
||||
public function getDefault() {
|
||||
return new \Predis\Utilities\HashRing();
|
||||
return new \Predis\Distribution\HashRing();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -353,7 +353,7 @@ abstract class Command {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getHash(IDistributionAlgorithm $distributor) {
|
||||
public function getHash(Distribution\IDistributionAlgorithm $distributor) {
|
||||
if (isset($this->_hash)) {
|
||||
return $this->_hash;
|
||||
}
|
||||
@@ -921,13 +921,6 @@ class ConnectionParameters {
|
||||
}
|
||||
}
|
||||
|
||||
interface IDistributionAlgorithm {
|
||||
public function add($node, $weight = null);
|
||||
public function remove($node);
|
||||
public function get($key);
|
||||
public function generateKey($value);
|
||||
}
|
||||
|
||||
interface IConnection {
|
||||
public function connect();
|
||||
public function disconnect();
|
||||
@@ -1108,9 +1101,9 @@ class Connection implements IConnection {
|
||||
class ConnectionCluster implements IConnection, \IteratorAggregate {
|
||||
private $_pool, $_distributor;
|
||||
|
||||
public function __construct(IDistributionAlgorithm $distributor = null) {
|
||||
public function __construct(Distribution\IDistributionAlgorithm $distributor = null) {
|
||||
$this->_pool = array();
|
||||
$this->_distributor = $distributor ?: new Utilities\HashRing();
|
||||
$this->_distributor = $distributor ?: new Distribution\HashRing();
|
||||
}
|
||||
|
||||
public function isConnected() {
|
||||
@@ -1529,23 +1522,18 @@ class RedisServer_vNext extends RedisServer_v2_0 {
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
namespace Predis\Utilities;
|
||||
namespace Predis\Distribution;
|
||||
|
||||
class Shared {
|
||||
public static function onCommunicationException(\Predis\CommunicationException $exception) {
|
||||
if ($exception->shouldResetConnection()) {
|
||||
$connection = $exception->getConnection();
|
||||
if ($connection->isConnected()) {
|
||||
$connection->disconnect();
|
||||
}
|
||||
}
|
||||
throw $exception;
|
||||
}
|
||||
interface IDistributionAlgorithm {
|
||||
public function add($node, $weight = null);
|
||||
public function remove($node);
|
||||
public function get($key);
|
||||
public function generateKey($value);
|
||||
}
|
||||
|
||||
class EmptyRingException extends \Exception { }
|
||||
|
||||
class HashRing implements \Predis\IDistributionAlgorithm {
|
||||
class HashRing implements IDistributionAlgorithm {
|
||||
const DEFAULT_REPLICAS = 128;
|
||||
const DEFAULT_WEIGHT = 100;
|
||||
private $_nodes, $_ring, $_ringKeys, $_ringKeysCount, $_replicas;
|
||||
@@ -1695,6 +1683,22 @@ class KetamaPureRing extends HashRing {
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
namespace Predis\Utilities;
|
||||
|
||||
class Shared {
|
||||
public static function onCommunicationException(\Predis\CommunicationException $exception) {
|
||||
if ($exception->shouldResetConnection()) {
|
||||
$connection = $exception->getConnection();
|
||||
if ($connection->isConnected()) {
|
||||
$connection->disconnect();
|
||||
}
|
||||
}
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
abstract class MultiBulkResponseIteratorBase implements \Iterator, \Countable {
|
||||
protected $_position, $_current, $_replySize;
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
$this->assertEquals('PING', $cmd->getCommandId());
|
||||
$this->assertFalse($cmd->closesConnection());
|
||||
$this->assertFalse($cmd->canBeHashed());
|
||||
$this->assertNull($cmd->getHash(new \Predis\Utilities\HashRing()));
|
||||
$this->assertNull($cmd->getHash(new \Predis\Distribution\HashRing()));
|
||||
$this->assertEquals("PING\r\n", $cmd());
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
$this->assertEquals('GET', $cmd->getCommandId());
|
||||
$this->assertFalse($cmd->closesConnection());
|
||||
$this->assertTrue($cmd->canBeHashed());
|
||||
$this->assertNotNull($cmd->getHash(new \Predis\Utilities\HashRing()));
|
||||
$this->assertNotNull($cmd->getHash(new \Predis\Distribution\HashRing()));
|
||||
$this->assertEquals("GET key\r\n", $cmd());
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
$this->assertEquals('SET', $cmd->getCommandId());
|
||||
$this->assertFalse($cmd->closesConnection());
|
||||
$this->assertTrue($cmd->canBeHashed());
|
||||
$this->assertNotNull($cmd->getHash(new \Predis\Utilities\HashRing()));
|
||||
$this->assertNotNull($cmd->getHash(new \Predis\Distribution\HashRing()));
|
||||
$this->assertEquals("SET key 5\r\nvalue\r\n", $cmd());
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
$this->assertEquals('MSET', $cmd->getCommandId());
|
||||
$this->assertFalse($cmd->closesConnection());
|
||||
$this->assertFalse($cmd->canBeHashed());
|
||||
$this->assertNull($cmd->getHash(new \Predis\Utilities\HashRing()));
|
||||
$this->assertNull($cmd->getHash(new \Predis\Distribution\HashRing()));
|
||||
$this->assertEquals("*5\r\n$4\r\nMSET\r\n$4\r\nkey1\r\n$6\r\nvalue1\r\n$4\r\nkey2\r\n$6\r\nvalue2\r\n", $cmd());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user