Files
shopPRO/autoload/Shared/Cache/RedisConnection.php
Jacek Pyziak 8e97413361 ver. 0.282: Banners frontend migration, Cache cleanup, Shared\Cache namespace
- Banners frontend: front\Views\Banners (new), BannerRepository +2 frontend methods,
  front\view\Site przepięty, usunięte front\factory\Banners i front\view\Banners
- Cache cleanup: eliminacja legacy class.Cache.php (file-based cache),
  13 metod front\factory przepiętych z \Cache::fetch/store na CacheHandler
- Shared\Cache namespace: CacheHandler i RedisConnection przeniesione do Shared\Cache\,
  60 odwołań CacheHandler i 12 odwołań RedisConnection przepiętych,
  usunięte backward-compat wrappery class.CacheHandler.php i class.RedisConnection.php
- Naprawione rozbieżności kluczy cache (random_products, category_name)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-16 21:25:50 +01:00

46 lines
1.1 KiB
PHP

<?php
namespace Shared\Cache;
class RedisConnection
{
private static $instance = null;
private $redis;
private function __construct()
{
global $config;
$this->redis = new \Redis();
try {
if (!$this->redis->connect($config['redis']['host'], $config['redis']['port'])) {
error_log("Nie udalo sie polaczyc z serwerem Redis.");
$this->redis = null;
return;
}
if (!$this->redis->auth($config['redis']['password'])) {
error_log("Autoryzacja do serwera Redis nie powiodla sie.");
$this->redis = null;
return;
}
} catch (\Exception $e) {
error_log("Blad podczas polaczenia z Redis: " . $e->getMessage());
$this->redis = null;
}
}
public static function getInstance()
{
if (self::$instance === null) {
self::$instance = new self();
}
return self::$instance;
}
public function getConnection()
{
return $this->redis;
}
}