SkillAgentSearch skills...

Hashring

Consistent hashing "hashring" implementation in php (using the same algorithm as libketama)

Install / Use

/learn @chxj1992/Hashring
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

HashRing Build Status

<a href="http://www.wtfpl.net/"><img src="http://www.wtfpl.net/wp-content/uploads/2012/12/wtfpl-badge-4.png" width="80" height="15" alt="WTFPL" /></a>

Implements consistent hashing that can be used when the number of server nodes can increase or decrease (like in memcached). The hashing ring is built using the same algorithm as libketama.

Inspired by a golang hashring library serialx/hashring.

Using

Install ::

composer require chxj1992/hashring:~1.0

Basic example usage ::

$memcacheServers = ["192.168.0.246:11212",
                    "192.168.0.247:11212",
                    "192.168.0.249:11212"];

$hashRing = new \Chxj1992\HashRing\HashRing($memcacheServers);
$server = $ring->getNode("my_key");

Using weights example ::

$weights = ["192.168.0.246:11212" => 1,
            "192.168.0.247:11212" => 2,
            "192.168.0.249:11212" => 1];

$hashRing = new \Chxj1992\HashRing\HashRing($weights);
$server = $hashRing->getNode("my_key");

Adding and removing nodes example ::

$memcacheServers = ["192.168.0.246:11212",
                    "192.168.0.247:11212",
                    "192.168.0.249:11212"];

$hashRing = new \Chxj1992\HashRing\HashRing($memcacheServers);
$hashRing = $hashRing->removeNode("192.168.0.246:11212");
$hashRing = $hashRing->addNode("192.168.0.250:11212");
$server = $hashRing->getNode("my_key");
View on GitHub
GitHub Stars6
CategoryDevelopment
Updated3y ago
Forks2

Languages

PHP

Security Score

75/100

Audited on Jul 23, 2022

No findings