Пример #1
0
 public function testThatFailoverIsInitiatedAndFailingCommandsAreRetried()
 {
     // 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);
     // configure how to back-off on reconnection attempts
     $backoffStrategy = new Incremental(500000, 2);
     $backoffStrategy->setMaxAttempts(10);
     // now we can start configuring the sentinel in the master discovery object
     $masterDiscovery = new MasterDiscovery('integrationtests');
     $masterDiscovery->setBackoffStrategy($backoffStrategy);
     $masterDiscovery->addSentinel($sentinel1);
     $masterDiscovery->addSentinel($sentinel2);
     $masterDiscovery->addSentinel($sentinel3);
     // configure the HAClient that we'll use to talk to the redis master as a proxy
     $HAClient = new HAClient($masterDiscovery);
     // simulate a segfault in 5s
     $this->debugSegfaultToMaster();
     for ($i = 1; $i <= 30; $i++) {
         $HAClient->incr(__METHOD__);
     }
     $this->assertEquals(30, $HAClient->get(__METHOD__), 'Test that all increment calls were executed');
 }
Пример #2
0
 public function testThatInfiniteLoopsOfRetriesArePrevented()
 {
     $this->setExpectedException('\\PSRedis\\Exception\\ConnectionError');
     // mock master node
     $master = \Phake::mock('\\PSRedis\\Client');
     \Phake::when($master)->get('test')->thenThrow(new ConnectionError());
     // mock master discovery
     $masterDiscovery = \Phake::mock('\\PSRedis\\MasterDiscovery');
     \Phake::when($masterDiscovery)->getMaster()->thenReturn($master);
     // testing proxy
     $haclient = new HAClient($masterDiscovery);
     $haclient->get('test');
 }
Пример #3
0
 /**
  * Get the config values for the redis database.
  *
  * @return array
  */
 public function getConfig()
 {
     return ['cluster' => Config::get('database.redis.cluster'), 'default' => ['host' => $this->HAClient->getIpAddress(), 'port' => $this->HAClient->getPort()]];
 }
 /**
  * {@inheritdoc}
  */
 public function write($sessionId, $sessionData)
 {
     return (bool) $this->redisClient->setex($sessionId, $this->ttlInSeconds, $sessionData);
 }