Skip to content

[RFC] Add support for setting SETNAME lazy #2893

Description

@lyrixx

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

Basically, I have this 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:

$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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions