tguyard/flexihash

Flexihash 一致性哈希库。

维护者

详细信息

github.com/tguyard/flexihash

源码

dev-psr-4 2015-08-12 13:35 UTC

This package is not auto-updated.

Last update: 2024-10-02 10:12:12 UTC


README

Build Status

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"

进一步阅读