#2893·phpredis

[RFC] Add support for setting SETNAME lazy

Author: lyrixxCreated Jul 21, 2026Updated Jul 21, 2026

Hello, I'm updating our codebase, to use the new "lazy" feature.

Basically, I have this diff

diff
@@ -8,24 +8,20 @@ class Redis extends \Redis
     private array $scriptHashes = [];
 
     public function __construct(
-        private readonly string $host = '127.0.0.1',
-        private readonly int $port = 6379,
-        private readonly int $timeout = 3,
+        string $host = '127.0.0.1',
+        int $port = 6379,
+        int $timeout = 3,
     ) {
-        parent::__construct();
-    }
-
-    public function connect2(?string $nameSuffix = null): void
-    {
-        if ($this->isConnected()) {
-            return;
-        }
-
-        parent::connect($this->host, $this->port, $this->timeout, null, 0, $this->timeout);
+        parent::__construct([
+            'host' => $host,
+            'port' => $port,
+            'connectTimeout' => $timeout,
+            'readTimeout' => $timeout,
+        ]);
 
         $name = 'backend/' . \PHP_SAPI;
-        if ($nameSuffix) {
-            $name = $name . '/' . $nameSuffix;
+        if (\PHP_SAPI === 'cli' && isset($_SERVER['argv'][1])) {
+            $name .= '/' . $_SERVER['argv'][1];
         }

         $this->client('SETNAME', $name);

Before, we have to create $redis, then call $redis->connect2(). Not it's over, and it's super cool.

However, I introduced a regression! The following line, triggers the connection:

php
$this->client('SETNAME', $name);

It would be awesome to be able to configure the name by setting it in the constructor, or if the instance could call public functon getclientName(): ?string

Thanks