PHP Class Flexihash\Flexihash

Show file Open project: pda/flexihash Class Usage Examples

Public Methods

Method Description
__construct ( Flexihash\Hasher\HasherInterface $hasher = null, integer $replicas = null ) Constructor.
__toString ( )
addTarget ( string $target, float $weight = 1 ) Add a target.
addTargets ( array $targets, float $weight = 1 ) : self Add a list of targets.
getAllTargets ( ) : array A list of all potential targets.
lookup ( string $resource ) : string Looks up the target for the given resource.
lookupList ( string $resource, integer $requestedCount ) : array Get a list of targets for the resource, in order of precedence.
removeTarget ( string $target ) : self Remove a target.

Private Methods

Method Description
sortPositionTargets ( ) Sorts the internal mapping (positions to targets) by position.

Method Details

__construct() public method

Constructor.
public __construct ( Flexihash\Hasher\HasherInterface $hasher = null, integer $replicas = null )
$hasher Flexihash\Hasher\HasherInterface
$replicas integer Amount of positions to hash each target to.

__toString() public method

public __toString ( )

addTarget() public method

Add a target.
public addTarget ( string $target, float $weight = 1 )
$target string
$weight float

addTargets() public method

Add a list of targets.
public addTargets ( array $targets, float $weight = 1 ) : self
$targets array
$weight float
return self fluent

getAllTargets() public method

A list of all potential targets.
public getAllTargets ( ) : array
return array

lookup() public method

Looks up the target for the given resource.
public lookup ( string $resource ) : string
$resource string
return string

lookupList() public method

Up to $requestedCount targets are returned, less if there are fewer in total.
public lookupList ( string $resource, integer $requestedCount ) : array
$resource string
$requestedCount integer The length of the list to return
return array List of targets

removeTarget() public method

Remove a target.
public removeTarget ( string $target ) : self
$target string
return self fluent