mirror of
https://github.com/predis/predis.git
synced 2026-08-24 13:39:27 +00:00
373d30b070
Status response objects are needed mostly to make it possible from the
client perspective to differentiate a status response with the payload
"OK" from a normale bulk reply containing "OK".
The biggest change is for commands returning +OK responses: these were
previously translated to TRUE (bool value), but they are now returned
as instances of Predis\Response\Status. Just to illustrate an example
of the possibilities with this change we will use SET since it is the
most widely used command returning +OK:
$response = $client->set('foo', 'bar');
echo $response; // 'OK'
$response == 'OK'; // TRUE
isset($response->ok); // TRUE
$response == true; // TRUE
$response === true; // FALSE
$response instanceof Predis\Response\ObjectInterface; // TRUE
$response instanceof Predis\Response\Status; // TRUE
For those checking responses returned by commands such as SET or PONG,
the breaking change basically lies in the usage of strict comparison:
doing $response === true will now evaluate to FALSE instead of TRUE.
By default Predis caches common status responses such as OK or QUEUED
to lower the memory usage when using pipelines or transactions.
168 lines
4.1 KiB
PHP
168 lines
4.1 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Predis package.
|
|
*
|
|
* (c) Daniele Alessandri <suppakilla@gmail.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Predis\Command;
|
|
|
|
/**
|
|
* @group commands
|
|
* @group realm-server
|
|
*/
|
|
class ServerConfigTest extends PredisCommandTestCase
|
|
{
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function getExpectedCommand()
|
|
{
|
|
return 'Predis\Command\ServerConfig';
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function getExpectedId()
|
|
{
|
|
return 'CONFIG';
|
|
}
|
|
|
|
/**
|
|
* @group disconnected
|
|
*/
|
|
public function testFilterArguments()
|
|
{
|
|
$arguments = array('GET', 'slowlog');
|
|
$expected = array('GET', 'slowlog');
|
|
|
|
$command = $this->getCommand();
|
|
$command->setArguments($arguments);
|
|
|
|
$this->assertSame($expected, $command->getArguments());
|
|
}
|
|
|
|
/**
|
|
* @group disconnected
|
|
*/
|
|
public function testParseResponseOfConfigGet()
|
|
{
|
|
$raw = array('slowlog-log-slower-than','10000','slowlog-max-len','64','loglevel','verbose');
|
|
$expected = array(
|
|
'slowlog-log-slower-than' => '10000',
|
|
'slowlog-max-len' => '64',
|
|
'loglevel' => 'verbose',
|
|
);
|
|
|
|
$command = $this->getCommand();
|
|
|
|
$this->assertSame($expected, $command->parseResponse($raw));
|
|
}
|
|
|
|
/**
|
|
* @group disconnected
|
|
*/
|
|
public function testParseResponseOfConfigSet()
|
|
{
|
|
$this->assertSame('OK', $this->getCommand()->parseResponse('OK'));
|
|
}
|
|
|
|
/**
|
|
* @group disconnected
|
|
*/
|
|
public function testParseResponseOfConfigResetstat()
|
|
{
|
|
$this->assertSame('OK', $this->getCommand()->parseResponse('OK'));
|
|
}
|
|
|
|
/**
|
|
* @group connected
|
|
*/
|
|
public function testReturnsListOfConfigurationValues()
|
|
{
|
|
$redis = $this->getClient();
|
|
|
|
$this->assertInternalType('array', $configs = $redis->config('GET', '*'));
|
|
$this->assertGreaterThan(1, count($configs));
|
|
$this->assertArrayHasKey('loglevel', $configs);
|
|
$this->assertArrayHasKey('appendonly', $configs);
|
|
$this->assertArrayHasKey('dbfilename', $configs);
|
|
}
|
|
|
|
/**
|
|
* @group connected
|
|
*/
|
|
public function testReturnsListOfOneConfigurationEntry()
|
|
{
|
|
$redis = $this->getClient();
|
|
|
|
$this->assertInternalType('array', $configs = $redis->config('GET', 'dbfilename'));
|
|
$this->assertEquals(1, count($configs));
|
|
$this->assertArrayHasKey('dbfilename', $configs);
|
|
}
|
|
|
|
/**
|
|
* @group connected
|
|
*/
|
|
public function testReturnsEmptyListOnUnknownConfigurationEntry()
|
|
{
|
|
$redis = $this->getClient();
|
|
|
|
$this->assertSame(array(), $redis->config('GET', 'foobar'));
|
|
}
|
|
|
|
/**
|
|
* @group connected
|
|
*/
|
|
public function testReturnsTrueOnSuccessfulConfiguration()
|
|
{
|
|
$redis = $this->getClient();
|
|
|
|
$previous = $redis->config('GET', 'loglevel');
|
|
|
|
$this->assertEquals('OK', $redis->config('SET', 'loglevel', 'notice'));
|
|
$this->assertSame(array('loglevel' => 'notice'), $redis->config('GET', 'loglevel'));
|
|
|
|
// We set the loglevel configuration to the previous value.
|
|
$redis->config('SET', 'loglevel', $previous['loglevel']);
|
|
}
|
|
|
|
/**
|
|
* @group connected
|
|
* @expectedException Predis\Response\ServerException
|
|
* @expectedExceptionMessage ERR Unsupported CONFIG parameter: foo
|
|
*/
|
|
public function testThrowsExceptionWhenSettingUnknownConfiguration()
|
|
{
|
|
$redis = $this->getClient();
|
|
|
|
$redis->config('SET', 'foo', 'bar');
|
|
}
|
|
|
|
/**
|
|
* @group connected
|
|
*/
|
|
public function testReturnsTrueOnResetstat()
|
|
{
|
|
$redis = $this->getClient();
|
|
|
|
$this->assertEquals('OK', $redis->config('RESETSTAT'));
|
|
}
|
|
|
|
/**
|
|
* @group connected
|
|
* @expectedException Predis\Response\ServerException
|
|
*/
|
|
public function testThrowsExceptionOnUnknownSubcommand()
|
|
{
|
|
$redis = $this->getClient();
|
|
|
|
$redis->config('FOO');
|
|
}
|
|
}
|