- 64
- 0
配置多个服务器,在 Illuminate\Cache\MemcachedConnector 使用addServer 添加进 memcached 具体见文档
cat config/cache.php
'memcached' => [
'driver' => 'memcached',
'servers' =>
[
[
'host' => '127.0.0.1', 'port' => 11211, 'weight' => 80
],
[
'host' => '127.0.0.1', 'port' => 11212, 'weight' => 20
],
],
https://laravel-china.org/top...
public function connect(array $servers)
{
$memcached = $this->getMemcached();
// For each server in the array, we'll just extract the configuration and add
// the server to the Memcached connection. Once we have added all of these
// servers we'll verify the connection is successful and return it back.
foreach ($servers as $server) {
$memcached->addServer(
$server['host'], $server['port'], $server['weight']
);
}
$memcachedStatus = $memcached->getVersion();
//Where a connection has failed to a server the version is returned as '255.255.255'.
array:2 [▼
"xxx:11211" => "1.5.5"
"xxx:11222" => "1.5.5"
]
if (! is_array($memcachedStatus)) {
throw new RuntimeException('No Memcached servers added.');
}
if (in_array('255.255.255', $memcachedStatus) && count(array_unique($memcachedStatus)) === 1) {
throw new RuntimeException('Could not establish Memcached connection.');
}
return $memcached;
}
cat Illuminate\Cache\Repository.php
public function get($key, $default = null)
{
//$this->store 来自Illuminate\Cache\MemcachedStore
dump($this->store->getmemcached()->getstats());//返回config/cache.php memcached servers数组服务器信息
$value = $this->store->get($key);
if (is_null($value))
{
$this->fireCacheEvent('missed', [$key]);
$value = value($default);
}
else
{
$this->fireCacheEvent('hit', [$key, $value]);
}
return $value;
}
cat bootstarp/app.php
$app['events']->listen('cache.write',function($key, $value, $time) use ($app){
dump(app('cache')->store(),app('cache.store')->getStore()->getMemcached()->getstats());
});
测试
echo \Cache::get('test');// 调用函数里 $this->store->getmemcached()->getstats() 输出的还是2个服务器信息 ["127.0.0.1:11221" => [],"127.0.0.1:11222" => [],],怎么知道获取 test 缓存的时候具体连接的哪个服务器呢?
1
打赏
收藏
点击回答
网站公告
- 扫一扫访问手机版
回答动态

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器更新之后。服务器里面有部分玩家要重新创建角色是怎么回事啊?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题函数计算不同地域的是不能用内网吧?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题ARMS可以创建多个应用嘛?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题在ARMS如何申请加入公测呀?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题前端小程序接入这个arms具体是如何接入监控的,这个init方法在哪里进行添加?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器刚到期,是不是就不能再导出存档了呢?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器的游戏版本不兼容 尝试更新怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器服务器升级以后 就链接不上了,怎么办?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器转移以后服务器进不去了,怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器修改参数后游戏进入不了,是什么情况?预计能赚取 0积分收益
- 回到顶部
- 回到顶部
