src/Topxia/Service/Common/Redis/ConsistentHashingRedis.php
(开头部分) 1KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
<?php
namespace Topxia\Service\Common\Redis;
use Redis;
use Flexihash\Flexihash;
class ConsistentHashingRedis
{
private $hash;
private $reidsPool;
public function __construct($config)
{
$this->hash = new Flexihash();
$servers = $config['servers'];
$redisServers = array();
foreach ($servers as $key => $value) {
try {
$key = $value['host'].':'.$value['port'];
$redis = new Redis();
$redis->pconnect($value['host'], $value['port'], $value['timeout'], $value['reserved'], $value['retry_interval']);
$redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
$this->reidsPool[$key] = $redis;
$redisServers[] = $key;
} catch (\Exception $e) {
throw $e;
}
}
$this->hash->addTargets($redisServers);
}
public function close()
{
}
public function __call($name, $arguments)
{
$key = $arguments[0];
$target = $this->hash->lookup($key);
$redis = $this->reidsPool[$target];
if (!method_exists($redis, $name)) {
throw new Exception('method not exists.');
}
return call_user_func_array(array($redis, $name), $arguments);
}
}
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。