Ejemplo n.º 1
0
 protected function activateNextConnection()
 {
     // this call will either return true or throw an exception, so we don't need the return value
     parent::activateNextConnection();
     // find out whether first conn is active or a different one
     if ($this->isFailoverActive()) {
         $time = $this->time->current();
         $this->failoverActiveSince = $time;
         // we set this one also so we don't immediately try to disable the newly created connection again
         $this->lastConnectionAttempt = $time;
         $this->log->info("Running in Failover mode since " . date('c', $time));
     }
     return true;
 }
Ejemplo n.º 2
0
 public function testRepeatedFailover()
 {
     $clientA = new PhpIRedisClient('someCircleA', 'localhost', 6379);
     $clientB = new PhpIRedisClient('someCircleB', 'unreachableHost', 6379);
     $clientC = new PhpIRedisClient('someCircleC', 'localhost', 6379);
     $redis = new FailoverWrapper(array($clientA, $clientB, $clientC));
     $this->assertTrue($redis->connect(null));
     $redis->del('testDeadConn');
     $this->assertEquals(1, $redis->incr('testDeadConn'));
     // now we leverage a ton of knowledge about the setup, but since we are in a unit test
     // and control everything, its fine
     // interupt the connection
     phpiredis_command_bs($this->readAttribute($clientA, 'connection'), array('QUIT'));
     $clientA->prepareConnect('unreachableHost');
     // everything should still work at this place, because there is a backup connection
     $this->assertEquals(1, $redis->get('testDeadConn'));
     $this->assertFalse($clientA->isconnected());
     $this->assertFalse($clientB->isconnected());
     $this->assertTrue($clientC->isconnected());
 }