alb/phpketama

v0.4.0 2023-07-10 10:05 UTC

This package is auto-updated.

Last update: 2024-09-10 12:49:08 UTC


README

这是一个libketama一致哈希库的纯PHP实现。

与libketama的兼容性

PHP Ketama使用与libketama相同的算法,并将始终返回与libketama相同的结果。

API不兼容。

速度

在PHP Ketama中加载缓存的连续文件速度更快。哈希速度较慢。根据包含的基准测试,当每个实例执行多达200次哈希时,这使得PHP Ketama比libketama更快。

使用方法

<?php

use Ketama\Ketama;
use Symfony\Component\Cache\Adapter\ApcuAdapter;
use Symfony\Component\Cache\Psr16Cache;

// Cache used to store the parsed continuum file
$cache = new Psr16Cache(new ApcuAdapter('mynamespace')

$ketama = new Ketama($cache);
$continuum = $ketama->createContinuum('/some/file');

// Lookup server
$ip = $continuum->getServer("some key");

连续文件

# server    weight
server1 1
server2 3
server3 1
server4 2