public function Init() { $this->hash = new ConsistentHash(); $this->MasterOrSlave = $ShmList = ShmConfig::getCacheAvailableAddress($this->config); //从内存中获得可用列表 $list = array(); if (empty($ShmList)) { //内存中没有,可能ping脚本没启,直接用配置 foreach ($this->config['nodes'] as $node) { $list[] = $node['master']; } } else { foreach ($ShmList as $node) { //false已过滤,主/从在逻辑上都hash主的值 $list[] = $node['master']['target']; } } $this->hash->addTargets($list); //传入逻辑结点列表 }