tguyard / flexihash
Flexihash 一致性哈希库。
dev-psr-4
2015-08-12 13:35 UTC
Requires
- php: >=5.4.0
Requires (Dev)
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2024-10-02 10:12:12 UTC
README
Flexihash 是一个小的 PHP 库,实现了 [一致性哈希],这对于分布式缓存非常有用。它需要 PHP5,并使用 PHPUnit 进行单元测试。
使用示例
<?php $hash = new Flexihash(); // bulk add $hash->addTargets(array('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"