PHP code example of jspeedz / php-consistent-hashing

1. Go to this page and download the library: Download jspeedz/php-consistent-hashing library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jspeedz / php-consistent-hashing example snippets


$hasher = new \Jspeedz\PhpConsistentHashing\MultiProbeConsistentHash();
// Choose which hash functions to use
$hasher->setHashFunctions((new \Jspeedz\PhpConsistentHashing\HashFunctions\Standard)());

$hasher->addNode('node1');
$hasher->addNode('node2');
$hasher->addNode('node2');

$node = $hasher->hash('some_key1');

$hasher->addNode('node1', 25);
$hasher->addNode('node2', 33.3);
$hasher->addNode('node2', 41.7);

$node = $hasher->hash('some_key1');