This commit is contained in:
2026-07-10 02:39:19 +03:30
parent d5639f05fc
commit 2b3c03b62a
2 changed files with 53 additions and 19 deletions

View File

@@ -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;
}