Issue Bug Closed

#98624Redis connect using Socket

Josef Glatz 10/15/22, 19:43 updated 04/14/23, 21:23

Description

The RedisBackend class always uses a port to connect. When you only have redis unix socket you can’t use a port for the redis connection.

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.

History 2

  1. Stefan Bürk commented and changed status New Needs Feedback 10/16/22, 18:10

    Have you tried to provide the path to the socket as `hostname` ?

    The used php extension and thus the Redis class have no dedicated socket file/path argument like for example mysqli and others.

    Here, some basic examples to connect from the redis php-extension readme:

    $redis->connect('127.0.0.1', 6379);
    $redis->connect('127.0.0.1'); // port 6379 by default
    $redis->connect('tls://127.0.0.1', 6379); // enable transport level security.
    $redis->connect('tls://127.0.0.1'); // enable transport level security, port 6379 by default.
    $redis->connect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout.
    $redis->connect('/tmp/redis.sock'); // unix domain socket.
    $redis->connect('127.0.0.1', 6379, 1, '', 100); // 1 sec timeout, 100ms delay between reconnection attempts.
    $redis->connect('/tmp/redis.sock', 0, 1.5, NULL, 0, 1.5); // Unix socket with 1.5s timeouts (connect and read)
    
    /* With PhpRedis >= 5.3.0 you can specify authentication and stream information on connect */
    $redis->connect('127.0.0.1', 6379, 1, '', 0, 0, ['auth' => ['phpredis', 'phpredis']]);

    The corresponding RedisBackend uses following code to create the native redis client instance:

            $this->redis = new \Redis();
            try {
                if ($this->persistentConnection) {
                    $this->connected = $this->redis->pconnect($this->hostname, $this->port, $this->connectionTimeout, (string)$this->database);
                } else {
                    $this->connected = $this->redis->connect($this->hostname, $this->port, $this->connectionTimeout);
                }
            } catch (\Exception $e) {
                $this->logger->alert('Could not connect to redis server.', ['exception' => $e]);
            }

    So I would give it a try to configure the socket name as hostname for the redis backend. ( `hostname` key of the redis configuration ). If that works we may extend the documentation and eventuall labels, but otherwise I guess we do not have to do anything technically about it and it should work that way.

    Can you try it and give feedback than ?

  2. Benni Mack commented and changed status Needs Feedback Closed 04/14/23, 21:23

    housekeeping: closing this issue due to lack of feedback, Josef, I can re-open the issue, feel free to contact me.