2017 © Pedro Peláez
 

library consistenthash

PHPX Consistent Hash Library

image

phpx/consistenthash

PHPX Consistent Hash Library

  • Sunday, May 25, 2014
  • by PsyduckMans
  • Repository
  • 1 Watchers
  • 1 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

PHPX-ConsistentHash

PHPX/ConsistentHash is a PHP library which implements [http://en.wikipedia.org/wiki/Consistent_hashing consistent hashing], which is most useful in distributed caching. The implement of \PHPX\ConsistentHash\Impl\Flexihash refer to Flexihash(https://github.com/pda/flexihash), (*1)

Usage Example

<?php
use PHPX\ConsistentHash\Hasher\Flexihash\Crc32Hasher;
use PHPX\ConsistentHash\Impl\Flexihash;
use PHPX\ConsistentHash\TargetUnit;
use PHPX\ConsistentHash\Target\HostTarget;

$hashSpace = new Flexihash(new Crc32Hasher());

// bulk add
$targetUnits = new \ArrayIterator(array(
    new TargetUnit(new HostTarget('redis-a', 6379), 1),
    new TargetUnit(new HostTarget('redis-b', 6379), 3),
    new TargetUnit(new HostTarget('redis-c', 6379), 2.5)
));
$hashSpace->addTargets($targetUnits);

// simple lookup
$hashSpace->lookup('object-a'); // "redis-a"
$hashSpace->lookup('object-b'); // "redis-b"

// add and remove
$weight = 20.3;
$hashSpace
  ->addTarget(new TargetUnit(new HostTarget('redis-d', 6379), $weight))
  ->removeTarget(new HostTarget('redis-a', 6379));

// lookup with next-best fallback (for redundant writes)
$hashSpace->lookupList('object', 2); // ["redis-b", "redis-d"]

// remove redis-b, expect object to hash to redis-d
$hashSpace->removeTarget(new HostTarget('redis-b', 6379));
$hashSpace->lookup('object'); // "redis-d"

The Versions

25/05 2014

dev-master

9999999-dev https://ninth.not-bad.org

PHPX Consistent Hash Library

  Sources   Download

MIT License

The Requires

  • php >=5.3.3

 

The Development Requires

cache library memcached hash open source extenstion consistent hash phpx