connect($host, (int)$port, 2.5)) { throw new \RuntimeException("Could not connect to Redis server at {$host}:{$port}"); } // Authenticate if password is provided if ($password) { if (!$redis->auth($password)) { throw new \RuntimeException("Redis authentication failed for host {$host}:{$port}."); } } // Set prefix for Saqel to avoid collisions $redis->setOption(\Redis::OPT_PREFIX, 'saqel:'); self::$instance = $redis; } catch (\Exception $e) { error_log("Redis Connection Error: " . $e->getMessage()); throw new \RuntimeException("Redis connection failed ({$host}:{$port}): " . $e->getMessage()); } } return self::$instance; } /** * Helper to close the connection explicitly */ public static function close(): void { if (self::$instance !== null) { self::$instance->close(); self::$instance = null; } } }