mirror of
https://github.com/predis/predis.git
synced 2026-08-30 04:02:22 +00:00
Minor optimization in the HashRing class when adding/removing nodes from the ring
This commit is contained in:
+4
-2
@@ -679,8 +679,9 @@ class HashRing {
|
||||
}
|
||||
|
||||
public function add($node) {
|
||||
$nodeHash = (string) $node;
|
||||
for ($i = 0; $i < self::NUMBER_OF_REPLICAS; $i++) {
|
||||
$key = crc32((string)$node . ':' . $i);
|
||||
$key = crc32($nodeHash . ':' . $i);
|
||||
$this->_ring[$key] = $node;
|
||||
}
|
||||
ksort($this->_ring, SORT_NUMERIC);
|
||||
@@ -688,8 +689,9 @@ class HashRing {
|
||||
}
|
||||
|
||||
public function remove($node) {
|
||||
$nodeHash = (string) $node;
|
||||
for ($i = 0; $i < self::NUMBER_OF_REPLICAS; $i++) {
|
||||
$key = crc32((string)$node . '_' . $i);
|
||||
$key = crc32($nodeHash . '_' . $i);
|
||||
unset($this->_ring[$key]);
|
||||
$this->_ringKeys = array_filter($this->_ringKeys, function($rk) use($key) {
|
||||
return $rk !== $key;
|
||||
|
||||
Reference in New Issue
Block a user