예제 #1
0
 /**
  * @return Client\ClientAdapter
  * @throws \PSRedis\Exception\ConfigurationError
  * @throws \PSRedis\Exception\ConnectionError
  */
 public function getMaster()
 {
     if (is_null($this->master)) {
         $this->master = $this->masterDiscovery->getMaster();
     }
     return $this->master;
 }
예제 #2
0
 /**
  * Proxies a call to a non-existing method in this object to the redis client
  *
  * @param $name
  * @param array $arguments
  * @return mixed
  */
 private function proxyFunctionCallToMaster($name, array $arguments)
 {
     if ($this->masterIsUnknown()) {
         $this->master = $this->masterDiscovery->getMaster();
     }
     return call_user_func_array(array($this->master, $name), $arguments);
 }
예제 #3
0
 public function testDiscoveryWithBackoffFailsWhenSentinelsStayOffline()
 {
     $this->setExpectedException('\\PSRedis\\Exception\\ConnectionError', 'All sentinels are unreachable');
     // disable sentinel on all nodes
     $this->disableSentinelAt('192.168.50.40');
     $this->disableSentinelAt('192.168.50.41');
     $this->disableSentinelAt('192.168.50.30');
     // we need a factory to create the clients
     $clientFactory = new PredisClientCreator();
     // we need an adapter for each sentinel client too!
     $clientAdapter = new PredisClientAdapter($clientFactory, Client::TYPE_SENTINEL);
     $sentinel1 = new Client('192.168.50.40', '26379', $clientAdapter);
     $clientAdapter = new PredisClientAdapter($clientFactory, Client::TYPE_SENTINEL);
     $sentinel2 = new Client('192.168.50.41', '26379', $clientAdapter);
     $clientAdapter = new PredisClientAdapter($clientFactory, Client::TYPE_SENTINEL);
     $sentinel3 = new Client('192.168.50.30', '26379', $clientAdapter);
     // now we can start discovering where the master is
     $masterDiscovery = new MasterDiscovery('integrationtests');
     $masterDiscovery->addSentinel($sentinel1);
     $masterDiscovery->addSentinel($sentinel2);
     $masterDiscovery->addSentinel($sentinel3);
     // configure a backoff strategy
     $incrementalBackoff = new Incremental(500, 1.5);
     $incrementalBackoff->setMaxAttempts(5);
     $masterDiscovery->setBackoffStrategy($incrementalBackoff);
     // try to discover the master
     $master = $masterDiscovery->getMaster();
 }
예제 #4
0
 /**
  * @group regression
  * @group issue-9
  */
 public function testThatABackoffStrategyIsResetWhenStartingTheMasterDiscovery()
 {
     $backoff = new Incremental(0, 1);
     $backoff->setMaxAttempts(2);
     $sentinel1 = $this->mockOfflineSentinel();
     $masterDiscovery = new MasterDiscovery('online-sentinel');
     $masterDiscovery->setBackoffStrategy($backoff);
     $masterDiscovery->addSentinel($sentinel1);
     try {
         $masterNode = $masterDiscovery->getMaster();
     } catch (ConnectionError $e) {
         // we expect this to fail as no sentinels are online
     }
     // add a sentinel that fails first, but succeeds after back-off (the bug, if present, will prevent reconnection of sentinels after backoff)
     $sentinel2 = $this->mockTemporaryOfflineSentinel();
     $masterDiscovery->addSentinel($sentinel2);
     // try to discover the master node
     $masterNode = $masterDiscovery->getMaster();
     $this->assertInstanceOf('\\PSRedis\\Client', $masterNode, 'When backing off is reset on each discovery, we should have received the master node here');
 }