public function testAppendToLog()
 {
     $redis = new PhpIRedisClient('someCircle');
     $redis->connect('localhost');
     $monitor = $this->getMockBuilder('\\Plista\\Core\\Redis\\Wrapper\\MonitoringWrapper')->setConstructorArgs(array($redis, '/tmp/xxx.log'))->setMethods(array('appendToLog'))->getMock();
     $monitor->expects($this->once())->method('appendToLog')->with($this->equalTo('SET testKey testValue 0'));
     $monitor->set('testKey', 'testValue', 0);
 }
 public function testLazyConnection()
 {
     $client = new PhpIRedisClient('clusterA');
     $redis = new LazyConnectionWrapper($client);
     $this->assertTrue($redis->connect('localhost'));
     $this->assertFalse($redis->isConnected());
     $this->assertFalse($client->isConnected());
     $this->assertEquals(true, $redis->setEx('testLazy', 60, 1));
     $this->assertTrue($redis->isConnected());
     $this->assertTrue($client->isConnected());
 }
示例#3
0
 public function tearDown()
 {
     // Flush redis after each run to prevent side effects
     try {
         if ($this->realRedis && $this->realRedis->isConnected()) {
             $this->realRedis->flushdb();
             $this->realRedis->disconnect();
         }
     } catch (Exception $e) {
         // we don't care about these exceptions
     }
 }
示例#4
0
 /**
  * Creates the actual Redis Client with a given name.
  * NOTE: the client is not yet connected to a server, although the connection parameters are set.
  *
  * @param string $name the name of the connection
  * @param array $config the connection parameters
  * @throws ConnectionParametersMissingException when no connection parameters are passed
  * @throws Exception when the selected client library is unknown
  * @return PhpRedisClient|PhpIRedisClient
  */
 private function createClient($name, array $config)
 {
     if (empty($config['host']) || empty($config['port'])) {
         throw new ConnectionParametersMissingException('invalid config, host or port missing for: ' . $name);
     }
     // use the default library for 'regular'
     if ($config['type'] == 'regular') {
         $config['type'] = $this->defaultClientLibrary;
     }
     /** @var Connection */
     $inst = null;
     // different implementations possible
     switch ($config['type']) {
         case 'phpredis':
             $inst = new PhpRedisClient($name);
             break;
         case 'phpiredis':
             $inst = new PhpIRedisClient($name);
             break;
         default:
             throw new Exception('Unknown client library: ' . $config['type']);
     }
     // we set the connection parameters here, since this is the only place where we know the individual
     // connection parameters. the controller later calls connect() which uses the parameters set here.
     $inst->prepareConnect($config['host'], $config['port']);
     return $inst;
 }
示例#5
0
 public function testBgSave()
 {
     $this->conn1->expects($this->once())->method('bgSave')->will($this->returnValue(true));
     $this->conn2->expects($this->once())->method('bgSave')->will($this->returnValue(true));
     $this->assertTrue($this->set->bgSave());
 }
 public function testLPush()
 {
     $this->read->del('testLPush');
     $this->assertEquals(1, $this->redis->lPush('testLPush', 'abc'));
     $this->assertEquals(0, $this->read->lLen('testLPush'));
 }
示例#7
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());
 }