First version, for githup; UNSTABLE, DO NOT USE!
This commit is contained in:
49
scripts/redis/connect-to-redis.php
Normal file
49
scripts/redis/connect-to-redis.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?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;
|
||||
}
|
||||
Reference in New Issue
Block a user