Add authentication to redis subsystem

This commit is contained in:
Greyscale 2021-01-30 10:57:28 +01:00
parent d77c860410
commit 8d7033c9b1
2 changed files with 7 additions and 1 deletions

View file

@ -352,6 +352,7 @@ class App
$logger,
$environmentService->get('REDIS_HOST', 'redis'),
$environmentService->get('REDIS_PORT', 6379),
$environmentService->get('REDIS_PASSWORD', null),
$environmentService->get('REDIS_TIMEOUT', 1.0)
);
});

View file

@ -222,6 +222,7 @@ class Redis
*/
private string $host;
private int $port;
private string $password;
private float $timeout;
private \Redis $redis;
private Logger $logger;
@ -229,12 +230,13 @@ class Redis
/** @var Lua\AbstractLuaExtension[] */
private array $scripts;
public function __construct(Logger $logger, string $host, int $port = 6379, float $timeout = 0.0)
public function __construct(Logger $logger, string $host, int $port = 6379, string $password = null, float $timeout = 0.0)
{
$this->logger = $logger;
$this->host = $host;
$this->port = $port;
$this->password = $password;
$this->timeout = $timeout;
$this->redis = new \Redis();
@ -297,6 +299,9 @@ class Redis
{
if (!$this->redis->isConnected()) {
@$this->redis->pconnect($this->host, $this->port, $this->timeout);
if($this->password){
$this->redis->auth($this->password);
}
$this->initialiseExtensions();
}
}