🚀 مُصادَق: الإطلاق الأولي للنظام المتكامل
This commit is contained in:
33
app/Core/Redis.php
Normal file
33
app/Core/Redis.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Core;
|
||||
|
||||
use Predis\Client;
|
||||
use Exception;
|
||||
|
||||
final class Redis
|
||||
{
|
||||
private static ?Client $instance = null;
|
||||
|
||||
public static function getInstance(): Client
|
||||
{
|
||||
if (self::$instance === null) {
|
||||
try {
|
||||
self::$instance = new Client([
|
||||
'scheme' => 'tcp',
|
||||
'host' => $_ENV['REDIS_HOST'] ?? '127.0.0.1',
|
||||
'port' => $_ENV['REDIS_PORT'] ?? 6379,
|
||||
'password' => $_ENV['REDIS_PASSWORD'] ?: null,
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
// If Redis fails, we might want to log it or handle gracefully
|
||||
// depending on how critical it is.
|
||||
throw new Exception("Redis Connection Error: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user