49 lines
947 B
PHP
49 lines
947 B
PHP
<?php
|
|
|
|
use Dotenv\Dotenv;
|
|
|
|
require __DIR__ . '/../../composer/vendor/autoload.php';
|
|
|
|
$envFile = realpath(__DIR__ . '/../../config/.env.redis');
|
|
|
|
if ($envFile === false) {
|
|
http_response_code(500);
|
|
echo json_encode([
|
|
'success' => false,
|
|
'message' => "Environment file not found"
|
|
]);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$envDir = dirname($envFile);
|
|
|
|
$dotenv = Dotenv::createImmutable($envDir, '.env.redis');
|
|
|
|
$dotenv->load();
|
|
} catch (Throwable $e) {
|
|
http_response_code(500);
|
|
echo json_encode([
|
|
'success' => false,
|
|
'message' => "Dotenv error"
|
|
]);
|
|
}
|
|
|
|
function connectToRedis(): bool
|
|
{
|
|
global $redis;
|
|
if ($redis instanceof Redis) {
|
|
return true;
|
|
}
|
|
|
|
$redis = new Redis();
|
|
|
|
if (!$redis->connect($_ENV['REDDIS_HOST'], $_ENV['REDDIS_PORT'])) {
|
|
return false;
|
|
}
|
|
|
|
if (!$redis->auth($_ENV['REDDIS_PASSWORD'])) {
|
|
return false;
|
|
}
|
|
return true;
|
|
} |