function testResponseReader_EmptyBulkResponse()
 {
     $protocol = new Predis\Protocol\Text\ComposableTextProtocol();
     $connection = new Predis\Network\ComposableStreamConnection(RC::getConnectionParameters(), $protocol);
     $client = new Predis\Client($connection);
     $this->assertTrue($client->set('foo', ''));
     $this->assertEquals('', $client->get('foo'));
     $this->assertEquals('', $client->get('foo'));
 }
Exemple #2
0
 function testResponseReader_OptionExceptionOnError()
 {
     $connection = new \Predis\TcpConnection(RC::getConnectionParameters());
     $responseReader = $connection->getResponseReader();
     $connection->rawCommand("SET key 5\r\nvalue\r\n");
     $rawCmdUnexpected = "LPUSH key 5\r\nvalue\r\n";
     $responseReader->setHandler(\Predis\Protocol::PREFIX_ERROR, new \Predis\ResponseErrorSilentHandler());
     $errorReply = $connection->rawCommand($rawCmdUnexpected);
     $this->assertType('\\Predis\\ResponseError', $errorReply);
     $this->assertEquals(RC::EXCEPTION_WRONG_TYPE, $errorReply->message);
     $responseReader->setHandler(\Predis\Protocol::PREFIX_ERROR, new \Predis\ResponseErrorHandler());
     RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function () use($connection, $rawCmdUnexpected) {
         $connection->rawCommand($rawCmdUnexpected);
     });
 }
Exemple #3
0
 function testResponseReader_OptionExceptionOnError()
 {
     $connection = new Predis_Connection(RC::getConnectionParameters());
     $responseReader = $connection->getResponseReader();
     $connection->rawCommand("*3\r\n\$3\r\nSET\r\n\$3\r\nkey\r\n\$5\r\nvalue\r\n");
     $rawCmdUnexpected = "*3\r\n\$5\r\nLPUSH\r\n\$3\r\nkey\r\n\$5\r\nvalue\r\n";
     $responseReader->setHandler(Predis_Protocol::PREFIX_ERROR, new Predis_ResponseErrorSilentHandler());
     $errorReply = $connection->rawCommand($rawCmdUnexpected);
     $this->assertType('Predis_ResponseError', $errorReply);
     $this->assertEquals(RC::EXCEPTION_WRONG_TYPE, $errorReply->message);
     $responseReader->setHandler(Predis_Protocol::PREFIX_ERROR, new Predis_ResponseErrorHandler());
     $thrownException = null;
     try {
         $connection->rawCommand($rawCmdUnexpected);
     } catch (Predis_ServerException $exception) {
         $thrownException = $exception;
     }
     $this->assertType('Predis_ServerException', $thrownException);
     $this->assertEquals(RC::EXCEPTION_WRONG_TYPE, $thrownException->getMessage());
 }
 function testResponseReader_OptionExceptionOnError()
 {
     $connection = new Predis_Connection(RC::getConnectionParameters());
     $responseReader = $connection->getResponseReader();
     $connection->rawCommand("*3\r\n\$3\r\nSET\r\n\$3\r\nkey\r\n\$5\r\nvalue\r\n");
     $rawCmdUnexpected = "*3\r\n\$5\r\nLPUSH\r\n\$3\r\nkey\r\n\$5\r\nvalue\r\n";
     $responseReader->setOption('throw_on_error', false);
     $errorReply = $connection->rawCommand($rawCmdUnexpected);
     $this->assertInstanceOf('Predis_ResponseError', $errorReply);
     $this->assertEquals(RC::EXCEPTION_WRONG_TYPE, $errorReply->message);
     $responseReader->setOption('throw_on_error', true);
     $thrownException = null;
     try {
         $connection->rawCommand($rawCmdUnexpected);
     } catch (Predis_ServerException $exception) {
         $thrownException = $exception;
     }
     $this->assertInstanceOf('Predis_ServerException', $thrownException);
     $this->assertEquals(RC::EXCEPTION_WRONG_TYPE, $thrownException->getMessage());
 }
 function testResponseReader_OptionExceptionOnError()
 {
     $connection = new \Predis\Connection(RC::getConnectionParameters());
     $responseReader = $connection->getResponseReader();
     $connection->rawCommand("*3\r\n\$3\r\nSET\r\n\$3\r\nkey\r\n\$5\r\nvalue\r\n");
     $rawCmdUnexpected = "*3\r\n\$5\r\nLPUSH\r\n\$3\r\nkey\r\n\$5\r\nvalue\r\n";
     $responseReader->setOption('throw_on_error', false);
     $errorReply = $connection->rawCommand($rawCmdUnexpected);
     $this->assertInstanceOf('\\Predis\\ResponseError', $errorReply);
     $this->assertEquals(RC::EXCEPTION_WRONG_TYPE, $errorReply->message);
     $responseReader->setOption('throw_on_error', true);
     RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function () use($connection, $rawCmdUnexpected) {
         $connection->rawCommand($rawCmdUnexpected);
     });
 }