Bug #98624
closedRedis connect using Socket
0%
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.
Updated by Stefan Bürk about 2 years ago
- Status changed from New to Needs Feedback
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 ?
Updated by Benni Mack over 1 year ago
- Status changed from Needs Feedback to Closed
housekeeping: closing this issue due to lack of feedback, Josef, I can re-open the issue, feel free to contact me.