PHP code example of chxj1992 / hashring

1. Go to this page and download the library: Download chxj1992/hashring 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/ */

    

chxj1992 / hashring example snippets


$memcacheServers = ["192.168.0.246:11212",
                    "192.168.0.247:11212",
                    "192.168.0.249:11212"];

$hashRing = new \Chxj1992\HashRing\HashRing($memcacheServers);
$server = $ring->getNode("my_key");

$weights = ["192.168.0.246:11212" => 1,
            "192.168.0.247:11212" => 2,
            "192.168.0.249:11212" => 1];

$hashRing = new \Chxj1992\HashRing\HashRing($weights);
$server = $hashRing->getNode("my_key");

$memcacheServers = ["192.168.0.246:11212",
                    "192.168.0.247:11212",
                    "192.168.0.249:11212"];

$hashRing = new \Chxj1992\HashRing\HashRing($memcacheServers);
$hashRing = $hashRing->removeNode("192.168.0.246:11212");
$hashRing = $hashRing->addNode("192.168.0.250:11212");
$server = $hashRing->getNode("my_key");