mirror of
https://github.com/predis/predis.git
synced 2026-09-12 03:17:22 +00:00
Disable CLIENT SETINFO calls by default (#1399)
Add `client_info` parameter
This commit is contained in:
@@ -175,7 +175,7 @@ class Factory implements FactoryInterface
|
||||
);
|
||||
}
|
||||
|
||||
if (!$connection instanceof RelayConnection) {
|
||||
if ($parameters->client_info ?? false && !$connection instanceof RelayConnection) {
|
||||
$connection->addConnectCommand(
|
||||
new RawCommand('CLIENT', ['SETINFO', 'LIB-NAME', 'predis'])
|
||||
);
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace Predis\Connection;
|
||||
* @property string $database Database index (see the SELECT command).
|
||||
* @property bool $async_connect Performs the connect() operation asynchronously.
|
||||
* @property bool $tcp_nodelay Toggles the Nagle's algorithm for coalescing.
|
||||
* @property bool $client_info Whether to set LIB-NAME and LIB-VER when connecting.
|
||||
* @property bool $cache (Relay only) Whether to use in-memory caching.
|
||||
* @property string $serializer (Relay only) Serializer used for data serialization.
|
||||
* @property string $compression (Relay only) Algorithm used for data compression.
|
||||
|
||||
@@ -1258,12 +1258,27 @@ class ClientTest extends PredisTestCase
|
||||
* @group relay-incompatible
|
||||
* @requiresRedisVersion >= 7.2.0
|
||||
*/
|
||||
public function testSetClientInfoOnConnection(): void
|
||||
public function testDoNoSetClientInfoOnConnection(): void
|
||||
{
|
||||
$client = new Client($this->getParameters());
|
||||
$libName = $client->client('LIST')[0]['lib-name'];
|
||||
$libVer = $client->client('LIST')[0]['lib-ver'];
|
||||
|
||||
$this->assertEmpty($libName);
|
||||
$this->assertEmpty($libVer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @group relay-incompatible
|
||||
* @requiresRedisVersion >= 7.2.0
|
||||
*/
|
||||
public function testSetClientInfoOnConnectionWhenEnabled(): void
|
||||
{
|
||||
$client = new Client($this->getParameters(['client_info' => true]));
|
||||
$libName = $client->client('LIST')[0]['lib-name'];
|
||||
$libVer = $client->client('LIST')[0]['lib-ver'];
|
||||
|
||||
$this->assertSame('predis', $libName);
|
||||
$this->assertSame(Client::VERSION, $libVer);
|
||||
}
|
||||
|
||||
@@ -304,12 +304,10 @@ class FactoryTest extends PredisTestCase
|
||||
->method('getParameters')
|
||||
->willReturn($parameters);
|
||||
$connection
|
||||
->expects($this->exactly(4))
|
||||
->expects($this->exactly(2))
|
||||
->method('addConnectCommand')
|
||||
->withConsecutive(
|
||||
[$this->isRedisCommand('AUTH', ['foobar'])],
|
||||
[$this->isRedisCommand('CLIENT', ['SETINFO', 'LIB-NAME', 'predis'])],
|
||||
[$this->isRedisCommand('CLIENT', ['SETINFO', 'LIB-VER', Client::VERSION])],
|
||||
[$this->isRedisCommand('SELECT', ['0'])]
|
||||
);
|
||||
|
||||
@@ -335,13 +333,9 @@ class FactoryTest extends PredisTestCase
|
||||
$connection->expects($this->once())
|
||||
->method('getParameters')
|
||||
->will($this->returnValue($parameters));
|
||||
$connection->expects($this->exactly(3))
|
||||
$connection->expects($this->once())
|
||||
->method('addConnectCommand')
|
||||
->withConsecutive(
|
||||
[$this->isRedisCommand('AUTH', ['foobar'])],
|
||||
[$this->isRedisCommand('CLIENT', ['SETINFO', 'LIB-NAME', 'predis'])],
|
||||
[$this->isRedisCommand('CLIENT', ['SETINFO', 'LIB-VER', Client::VERSION])]
|
||||
);
|
||||
->with($this->isRedisCommand('AUTH', ['foobar']));
|
||||
|
||||
$factory = new Factory();
|
||||
|
||||
@@ -366,13 +360,9 @@ class FactoryTest extends PredisTestCase
|
||||
$connection->expects($this->once())
|
||||
->method('getParameters')
|
||||
->will($this->returnValue($parameters));
|
||||
$connection->expects($this->exactly(3))
|
||||
$connection->expects($this->once())
|
||||
->method('addConnectCommand')
|
||||
->withConsecutive(
|
||||
[$this->isRedisCommand('AUTH', ['myusername', 'foobar'])],
|
||||
[$this->isRedisCommand('CLIENT', ['SETINFO', 'LIB-NAME', 'predis'])],
|
||||
[$this->isRedisCommand('CLIENT', ['SETINFO', 'LIB-VER', Client::VERSION])]
|
||||
);
|
||||
->with($this->isRedisCommand('AUTH', ['myusername', 'foobar']));
|
||||
|
||||
$factory = new Factory();
|
||||
|
||||
@@ -396,12 +386,8 @@ class FactoryTest extends PredisTestCase
|
||||
$connection->expects($this->once())
|
||||
->method('getParameters')
|
||||
->will($this->returnValue($parameters));
|
||||
$connection->expects($this->exactly(2))
|
||||
->method('addConnectCommand')
|
||||
->withConsecutive(
|
||||
[$this->isRedisCommand('CLIENT', ['SETINFO', 'LIB-NAME', 'predis'])],
|
||||
[$this->isRedisCommand('CLIENT', ['SETINFO', 'LIB-VER', Client::VERSION])]
|
||||
);
|
||||
$connection->expects($this->never())
|
||||
->method('addConnectCommand');
|
||||
|
||||
$factory = new Factory();
|
||||
|
||||
@@ -426,12 +412,8 @@ class FactoryTest extends PredisTestCase
|
||||
$connection->expects($this->once())
|
||||
->method('getParameters')
|
||||
->will($this->returnValue($parameters));
|
||||
$connection->expects($this->exactly(2))
|
||||
->method('addConnectCommand')
|
||||
->withConsecutive(
|
||||
[$this->isRedisCommand('CLIENT', ['SETINFO', 'LIB-NAME', 'predis'])],
|
||||
[$this->isRedisCommand('CLIENT', ['SETINFO', 'LIB-VER', Client::VERSION])]
|
||||
);
|
||||
$connection->expects($this->never())
|
||||
->method('addConnectCommand');
|
||||
|
||||
$factory = new Factory();
|
||||
|
||||
@@ -564,7 +546,7 @@ class FactoryTest extends PredisTestCase
|
||||
*/
|
||||
public function testSetClientNameAndVersionOnConnection(): void
|
||||
{
|
||||
$parameters = [];
|
||||
$parameters = ['client_info' => true];
|
||||
|
||||
$factory = new Factory();
|
||||
$connection = $factory->create($parameters);
|
||||
|
||||
Reference in New Issue
Block a user