Files
safe-paste/app/core/redis.php
2026-07-10 02:39:19 +03:30

32 lines
607 B
PHP

<?php
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();
try {
if (!@$redis->connect($config['redis']['host'], $config['redis']['port'])) {
$redis = null;
}
} catch (Throwable $e) {
$redis = null;
}
}
return $redis;
}