alb / phpketama
Installs: 33 284
Dependents: 1
Suggesters: 0
Security: 0
Stars: 7
Watchers: 3
Forks: 1
Open Issues: 0
Requires
- php: ^8.1
- psr/simple-cache: ^2.0.0
Requires (Dev)
- phpstan/phpstan: ^1.10.25
- phpunit/phpunit: ^10.2.3
- symfony/cache: ^5.4
This package is auto-updated.
Last update: 2024-11-10 13:11:19 UTC
README
This is a pure-PHP implementation of libketama, a consistent hashing library.
Compatibility with libketama
PHP Ketama uses the same algorithm as libketama, and will always return the same results as libketama.
The API is not compatible.
Speed
Loading a cached continuum file is faster in PHP Ketama. Hashing is slower. As per the included benchmark, this makes PHP Ketama faster than libketama when doing up to 200 hashes per instance.
Usage
<?php use Ketama\Ketama; use Symfony\Component\Cache\Adapter\ApcuAdapter; use Symfony\Component\Cache\Psr16Cache; // Cache used to store the parsed continuum file $cache = new Psr16Cache(new ApcuAdapter('mynamespace') $ketama = new Ketama($cache); $continuum = $ketama->createContinuum('/some/file'); // Lookup server $ip = $continuum->getServer("some key");
Continuum file:
# server weight
server1 1
server2 3
server3 1
server4 2