Author: Daniele Alessandri (suppakilla@gmail.com)
示例#1
0
 /**
  * {@inheritdoc}
  */
 public function getSlaves()
 {
     if ($this->slaves) {
         return array_values($this->slaves);
     }
     if ($this->updateSentinels) {
         $this->updateSentinels();
     }
     SENTINEL_QUERY:
     $sentinel = $this->getSentinelConnection();
     try {
         $slavesParameters = $this->querySentinelForSlaves($sentinel, $this->service);
         foreach ($slavesParameters as $slaveParameters) {
             $this->add($this->connectionFactory->create($slaveParameters));
         }
     } catch (ConnectionException $exception) {
         $this->sentinelConnection = null;
         goto SENTINEL_QUERY;
     }
     return array_values($this->slaves ?: array());
 }
示例#2
0
 /**
  * Discovers the replication configuration by contacting one of the slaves.
  *
  * @param NodeConnectionInterface $connection        Connection to one of the slaves.
  * @param FactoryInterface        $connectionFactory Connection factory instance.
  */
 protected function discoverFromSlave(NodeConnectionInterface $connection, FactoryInterface $connectionFactory)
 {
     $response = $connection->executeCommand(RawCommand::create('INFO', 'REPLICATION'));
     $replication = $this->handleInfoResponse($response);
     if ($replication['role'] !== 'slave') {
         throw new ClientException("Role mismatch (expected slave, got master) [{$connection}]");
     }
     $masterConnection = $connectionFactory->create(array('host' => $replication['master_host'], 'port' => $replication['master_port'], 'alias' => 'master'));
     $this->add($masterConnection);
     $this->discoverFromMaster($masterConnection, $connectionFactory);
 }