Add support for connecting to redis with an ssl file and password. #206

This commit is contained in:
Korina Cordero 2019-05-03 07:15:43 +00:00
parent afc07e7c68
commit a166a5f09a
2 changed files with 26 additions and 5 deletions

View file

@ -80,6 +80,9 @@ services:
$scheme: "%env(REDIS_CLIENT_SCHEME)%" $scheme: "%env(REDIS_CLIENT_SCHEME)%"
$host: "%env(REDIS_CLIENT_HOST)%" $host: "%env(REDIS_CLIENT_HOST)%"
$port: "%env(REDIS_CLIENT_PORT)%" $port: "%env(REDIS_CLIENT_PORT)%"
$cert_file: "%env(REDIS_CLIENT_CERTFILE)%"
$password: "%env(REDIS_CLIENT_PASSWORD)%"
$env_flag: "dev"
Catalyst\APIBundle\Security\APIKeyUserProvider: Catalyst\APIBundle\Security\APIKeyUserProvider:
arguments: arguments:

View file

@ -10,20 +10,38 @@ class RedisClient
protected $scheme; protected $scheme;
protected $host; protected $host;
protected $port; protected $port;
protected $cert_file;
protected $password;
protected $env_flag;
public function __construct($scheme, $host, $port) public function __construct($scheme, $host, $port, $cert_file, $password, $env_flag)
{ {
$this->scheme = $scheme; $this->scheme = $scheme;
$this->host = $host; $this->host = $host;
$this->port = $port; $this->port = $port;
$this->cert_file = $cert_file;
$this->password = $password;
$this->env_flag = $env_flag;
} }
public function getRedisClient() public function getRedisClient()
{ {
$this->redis = new PredisClient([ if ($this->env_flag == 'dev')
"scheme"=>$this->scheme, {
"host"=>$this->host, $this->redis = new PredisClient([
"port"=>$this->port]); "scheme"=>$this->scheme,
"host"=>$this->host,
"port"=>$this->port]);
}
else
{
$this->redis = new PredisClient([
"scheme"=>$this->scheme,
"host"=>$this->host,
"port"=>$this->port,
"ssl"=>["cafile"=>$cert_file, "verify_peer"=>true],
"password"=>$password]);
}
return $this->redis; return $this->redis;
} }
} }