|
@@ -14,24 +14,29 @@ final class Cache
|
|
|
*/
|
|
|
public function initRedis(): Redis
|
|
|
{
|
|
|
- $redis = new Redis();
|
|
|
- $redis->connect($_ENV['redis_host'], $_ENV['redis_port']);
|
|
|
-
|
|
|
- if ($_ENV['redis_password'] !== '') {
|
|
|
- $redis->auth($_ENV['redis_password']);
|
|
|
- }
|
|
|
-
|
|
|
- return $redis;
|
|
|
+ return new Redis(self::getRedisConfig());
|
|
|
}
|
|
|
|
|
|
public static function getRedisConfig(): array
|
|
|
{
|
|
|
- return [
|
|
|
+ $config = [
|
|
|
'host' => $_ENV['redis_host'],
|
|
|
'port' => $_ENV['redis_port'],
|
|
|
- 'connectTimeout' => $_ENV['redis_timeout'],
|
|
|
- 'auth' => [$_ENV['redis_username'], $_ENV['redis_password']],
|
|
|
- 'ssl' => ['verify_peer' => $_ENV['redis_ssl']],
|
|
|
+ 'connectTimeout' => $_ENV['redis_connect_timeout'],
|
|
|
+ 'readTimeout' => $_ENV['redis_read_timeout'],
|
|
|
];
|
|
|
+
|
|
|
+ if ($_ENV['redis_username'] !== '') {
|
|
|
+ $config['auth']['user'] = $_ENV['redis_username'];
|
|
|
+ }
|
|
|
+ if ($_ENV['redis_password'] !== '') {
|
|
|
+ $config['auth']['pass'] = $_ENV['redis_password'];
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($_ENV['redis_ssl'] === true) {
|
|
|
+ $config['ssl'] = $_ENV['redis_ssl_context'];
|
|
|
+ }
|
|
|
+
|
|
|
+ return $config;
|
|
|
}
|
|
|
}
|