fix: bug
This commit is contained in:
@@ -1,14 +1,31 @@
|
||||
<?php
|
||||
|
||||
function redisClient(): Redis
|
||||
function redisClient(): ?Redis
|
||||
{
|
||||
static $redis = null;
|
||||
static $initialized = false;
|
||||
|
||||
if ($initialized) {
|
||||
return $redis;
|
||||
}
|
||||
|
||||
$initialized = true;
|
||||
|
||||
if (!class_exists('Redis')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($redis === null) {
|
||||
$config = require __DIR__ . '/../config/config.php';
|
||||
$redis = new Redis();
|
||||
if (!@$redis->connect($config['redis']['host'], $config['redis']['port'])) {
|
||||
throw new RuntimeException('Redis connection failed.');
|
||||
try {
|
||||
if (!@$redis->connect($config['redis']['host'], $config['redis']['port'])) {
|
||||
$redis = null;
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
$redis = null;
|
||||
}
|
||||
}
|
||||
|
||||
return $redis;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user