Credis_Cluster::hash PHP Метод

hash() публичный Метод

Get client index for a key by searching ring with binary search
public hash ( string $key ) : integer
$key string The key to hash
Результат integer The index of the client object associated with the hash of the key
    public function hash($key)
    {
        $needle = hexdec(substr(md5($key), 0, 7));
        $server = $min = 0;
        $max = count($this->nodes) - 1;
        while ($max >= $min) {
            $position = (int) (($min + $max) / 2);
            $server = $this->nodes[$position];
            if ($needle < $server) {
                $max = $position - 1;
            } else {
                if ($needle > $server) {
                    $min = $position + 1;
                } else {
                    break;
                }
            }
        }
        return $this->ring[$server];
    }