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];
}