juklicek / flexihash
Flexihash 是一个实现一致性哈希的轻量级 PHP 库。
dev-master
2022-04-27 09:23 UTC
Requires
- php: >=5.2.0
This package is not auto-updated.
Last update: 2024-09-26 18:57:42 UTC
README
Flexihash 是一个实现 [http://en.wikipedia.org/wiki/Consistent_hashing 一致性哈希] 的轻量级 PHP 库,在分布式缓存中非常有用。它需要 PHP5,并使用 [http://simpletest.org/ SimpleTest] 进行单元测试。
使用示例
<?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"