Memcached 具體連線的哪個伺服器?

lovecn發表於2018-10-10

配置多個伺服器,在 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
                ],
            ],

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陣列伺服器資訊  
"127.0.0.1:11221" => [],"127.0.0.1:11222" => [],
        $value = $this->store->get($key);

        if (is_null($value))
        {
            $this->fireCacheEvent('missed', [$key]);

            $value = value($default);
        }
        else
        {
            $this->fireCacheEvent('hit', [$key, $value]);
        }

        return $value;
    }

測試

echo \Cache::get('test');// $this->store->getmemcached()->getstats() 輸出的還是多個伺服器資訊,怎麼知道具體連線的哪個伺服器呢?

本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章