コード例 #1
0
ファイル: PredisShared.php プロジェクト: rmoorman/web-bench
 private static function createConnection()
 {
     $serverProfile = Predis_RedisServerProfile::get('2.2');
     $connection = new Predis_Client(RC::getConnectionArguments(), $serverProfile);
     $connection->connect();
     $connection->select(RC::DEFAULT_DATABASE);
     return $connection;
 }
コード例 #2
0
ファイル: PredisShared.php プロジェクト: GunioRobot/predis
 public static function createConnection(array $additional = array())
 {
     $serverProfile = Predis\Profiles\ServerProfile::get(self::SERVER_VERSION);
     $connection = new Predis\Client(RC::getConnectionArguments($additional), $serverProfile);
     $connection->connect();
     $connection->select(RC::DEFAULT_DATABASE);
     return $connection;
 }
コード例 #3
0
 function testClientInitialization_ClusterConnectionParameters()
 {
     $params1 = array_merge(RC::getConnectionArguments(), array('connection_timeout' => 10, 'read_write_timeout' => 30));
     $params2 = RC::getConnectionParametersArgumentsString($params1);
     $params3 = new Predis\ConnectionParameters($params1);
     $params4 = new Predis\Network\StreamConnection($params3);
     $client1 = new Predis\Client(array($params1, $params2, $params3, $params4));
     foreach ($client1->getConnection() as $connection) {
         $parameters = $connection->getParameters();
         $this->assertEquals($params1['host'], $parameters->host);
         $this->assertEquals($params1['port'], $parameters->port);
         $this->assertEquals($params1['connection_timeout'], $parameters->connection_timeout);
         $this->assertEquals($params1['read_write_timeout'], $parameters->read_write_timeout);
         $this->assertNull($parameters->password);
     }
     $connectionCluster = $client1->getConnection();
     $client2 = new Predis\Client($connectionCluster);
     $this->assertSame($connectionCluster, $client2->getConnection());
 }
コード例 #4
0
 function testConnection_ReadTimeout()
 {
     $timeout = 1;
     $args = array_merge(RC::getConnectionArguments(), array('read_write_timeout' => $timeout));
     $cmdFake = \Predis\RedisServerProfile::getDefault()->createCommand('ping');
     $connection = new \Predis\Connection(new \Predis\ConnectionParameters($args));
     $expectedMessage = 'Error while reading line from the server';
     $start = time();
     RC::testForCommunicationException($this, $expectedMessage, function () use($connection, $cmdFake) {
         $connection->readResponse($cmdFake);
     });
     $this->assertEquals((double) (time() - $start), $timeout, '', 1);
 }
コード例 #5
0
 function testConnection_ReadTimeout()
 {
     $timeout = 1;
     $args = array_merge(RC::getConnectionArguments(), array('read_write_timeout' => $timeout));
     $cmdFake = Predis_RedisServerProfile::getDefault()->createCommand('ping');
     $connection = new Predis_Connection(new Predis_ConnectionParameters($args));
     $expectedMessage = 'Error while reading line from the server';
     $start = time();
     $thrownException = null;
     try {
         $connection->readResponse($cmdFake);
     } catch (Predis_CommunicationException $exception) {
         $thrownException = $exception;
     }
     $this->assertInstanceOf('Predis_CommunicationException', $thrownException);
     $this->assertEquals($expectedMessage, $thrownException->getMessage());
     $this->assertEquals((double) (time() - $start), $timeout, '', 1);
 }