flexihash / flexihash
Flexihash是一个小的PHP库,实现了一致性哈希,这在分布式缓存中非常有用。它需要PHP5,并使用PHPUnit进行单元测试。
v3.0.0
2020-08-07 00:58 UTC
Requires
- php: >=7.2.0
Requires (Dev)
- php-coveralls/php-coveralls: ^2.2
- phpunit/phpunit: ^8
- squizlabs/php_codesniffer: 3.*
- symfony/config: ^5.1.3
- symfony/console: ^5.1.3
- symfony/filesystem: ^5.1.3
- symfony/stopwatch: ^5.1.3
- symfony/yaml: ^5.1.3
This package is not auto-updated.
Last update: 2024-09-20 04:15:28 UTC
README
Flexihash是一个小的PHP库,实现了一致性哈希,这在分布式缓存中非常有用。它需要PHP5,并使用PHPUnit进行单元测试。
安装
Composer是推荐的安装方法。您可以在Packagist上找到flexihash,因此安装非常简单
composer require flexihash/flexihash
或在你的composer.json
{ "require": { "flexihash/flexihash": "^3.0.0" } }
使用
$hash = new Flexihash(); // bulk add $hash->addTargets(['cache-1', 'cache-2', 'cache-3']); // simple lookup $hash->lookup('object-a'); // "cache-1" $hash->lookup('object-b'); // "cache-2" // add and remove $hash ->addTarget('cache-4') ->removeTarget('cache-1'); // lookup with next-best fallback (for redundant writes) $hash->lookupList('object', 2); // ["cache-2", "cache-4"] // remove cache-2, expect object to hash to cache-4 $hash->removeTarget('cache-2'); $hash->lookup('object'); // "cache-4"
测试
单元测试
% vendor/bin/phpunit
基准测试
% vendor/bin/phpunit tests/BenchmarkTest.php