mirror of
https://github.com/predis/predis.git
synced 2026-10-15 08:17:05 +00:00
Change how Redis errors such as -ERR replies generates exceptions.
The "throw_errors" connection parameter has been removed and replaced by the new "exceptions" client option since exceptions on -ERR replies returned by Redis are not generated by connection classes anymore but are thrown by the client class and other abstractions such as pipeline contexts. This change does not affect much people using the Predis\Client class (aside from the different configuration) but gives much more flexibility to those building their own pieces of code around the internal classes of Predis.
This commit is contained in:
@@ -494,6 +494,48 @@ class MultiExecContextTest extends StandardTestCase
|
||||
$this->assertFalse($client->exists('foo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
*/
|
||||
public function testIntegrationThrowsExceptionOnRedisErrorInBlock()
|
||||
{
|
||||
$client = $this->getClient();
|
||||
$exception = null;
|
||||
$value = (string) rand();
|
||||
|
||||
try {
|
||||
$client->multiExec(function($tx) use($value) {
|
||||
$tx->set('foo', 'bar');
|
||||
$tx->lpush('foo', 'bar');
|
||||
$tx->set('foo', $value);
|
||||
});
|
||||
}
|
||||
catch (ServerException $ex) {
|
||||
$exception = $ex;
|
||||
}
|
||||
|
||||
$this->assertInstanceOf('Predis\ResponseErrorInterface', $exception);
|
||||
$this->assertSame($value, $client->get('foo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
*/
|
||||
public function testIntegrationReturnsErrorObjectOnRedisErrorInBlock()
|
||||
{
|
||||
$client = $this->getClient(array(), array('exceptions' => false));
|
||||
|
||||
$replies = $client->multiExec(function($tx) {
|
||||
$tx->set('foo', 'bar');
|
||||
$tx->lpush('foo', 'bar');
|
||||
$tx->echo('foobar');
|
||||
});
|
||||
|
||||
$this->assertTrue($replies[0]);
|
||||
$this->assertInstanceOf('Predis\ResponseErrorInterface', $replies[1]);
|
||||
$this->assertSame('foobar', $replies[2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
*/
|
||||
@@ -704,10 +746,11 @@ class MultiExecContextTest extends StandardTestCase
|
||||
* Returns a client instance connected to the specified Redis
|
||||
* server instance to perform integration tests.
|
||||
*
|
||||
* @return array Additional connection parameters.
|
||||
* @param array Additional connection parameters.
|
||||
* @param array Additional client options.
|
||||
* @return Client client instance.
|
||||
*/
|
||||
protected function getClient(Array $parameters = array())
|
||||
protected function getClient(Array $parameters = array(), Array $options = array())
|
||||
{
|
||||
$parameters = array_merge(array(
|
||||
'scheme' => 'tcp',
|
||||
@@ -716,7 +759,11 @@ class MultiExecContextTest extends StandardTestCase
|
||||
'database' => REDIS_SERVER_DBNUM,
|
||||
), $parameters);
|
||||
|
||||
$client = new Client($parameters, array('profile' => REDIS_SERVER_VERSION));
|
||||
$options = array_merge(array(
|
||||
'profile' => REDIS_SERVER_VERSION
|
||||
), $options);
|
||||
|
||||
$client = new Client($parameters, $options);
|
||||
|
||||
$client->connect();
|
||||
$client->flushdb();
|
||||
|
||||
Reference in New Issue
Block a user