From e7b89c14b798e64c5da4b23a0d3d03099b063d8a Mon Sep 17 00:00:00 2001 From: Lazizbek Ergashev Date: Fri, 11 Sep 2026 03:24:31 +0500 Subject: [PATCH] Fixed `client_info` connection parameter being ignored (#1722) * Fixed `client_info` connection parameter being ignored * Documented the default value of the `client_info` parameter --- CHANGELOG.md | 1 + src/Connection/Factory.php | 14 ++++++++------ src/Connection/ParametersInterface.php | 2 +- tests/Predis/Connection/FactoryTest.php | 18 ++++++++++++++++++ 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17bec36c..ebcf1a1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Changed ### Fixed - Fixed RESP3 double parsing returning positive `INF` for `-inf` payloads (#1716) +- Fixed `client_info` connection parameter being ignored (#1722) ## v3.6.0 (2026-08-14) ### Added diff --git a/src/Connection/Factory.php b/src/Connection/Factory.php index 5f1f568c..c9c44b7c 100644 --- a/src/Connection/Factory.php +++ b/src/Connection/Factory.php @@ -208,13 +208,15 @@ class Factory implements FactoryInterface ); } - $connection->addConnectCommand( - new RawCommand('CLIENT', ['SETINFO', 'LIB-NAME', $this->buildLibraryName()]) - ); + if ($parameters->client_info ?? true) { + $connection->addConnectCommand( + new RawCommand('CLIENT', ['SETINFO', 'LIB-NAME', $this->buildLibraryName()]) + ); - $connection->addConnectCommand( - new RawCommand('CLIENT', ['SETINFO', 'LIB-VER', Client::VERSION]) - ); + $connection->addConnectCommand( + new RawCommand('CLIENT', ['SETINFO', 'LIB-VER', Client::VERSION]) + ); + } if (isset($parameters->database) && strlen($parameters->database)) { $connection->addConnectCommand( diff --git a/src/Connection/ParametersInterface.php b/src/Connection/ParametersInterface.php index 521418f1..7cbe6343 100644 --- a/src/Connection/ParametersInterface.php +++ b/src/Connection/ParametersInterface.php @@ -36,7 +36,7 @@ use Predis\Retry\Retry; * @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 $client_info Whether to set LIB-NAME and LIB-VER when connecting, enabled by default. * @property Retry $retry Retry configuration * @property bool $cache (Relay only) Whether to use in-memory caching. * @property string $serializer (Relay only) Serializer used for data serialization. diff --git a/tests/Predis/Connection/FactoryTest.php b/tests/Predis/Connection/FactoryTest.php index 4ac2a126..15e527b2 100644 --- a/tests/Predis/Connection/FactoryTest.php +++ b/tests/Predis/Connection/FactoryTest.php @@ -585,6 +585,24 @@ class FactoryTest extends PredisTestCase $this->assertSame(['SETINFO', 'LIB-VER', Client::VERSION], $initCommands[2]->getArguments()); } + /** + * @group disconnected + * @return void + */ + public function testDoesNotSetClientNameAndVersionOnConnectionWithClientInfoDisabled(): void + { + $parameters = ['client_info' => false]; + + $factory = new Factory(); + $connection = $factory->create($parameters); + $initCommands = $connection->getInitCommands(); + + $this->assertCount(1, $initCommands); + $this->assertInstanceOf(RawCommand::class, $initCommands[0]); + $this->assertSame('HELLO', $initCommands[0]->getId()); + $this->assertSame([2, 'SETNAME', 'predis'], $initCommands[0]->getArguments()); + } + /** * @group disconnected */