import { Redis } from "npm:ioredis"; const VALKEY_URL = Deno.env.get("VALKEY_URL") || (import.meta.main ? "redis://auth-valkey:6379" : ""); export const valkey = VALKEY_URL ? new Redis(VALKEY_URL, { enableOfflineQueue: false, }) : {} as Redis; // Mock for tests export async function pingValkey(): Promise { if (!VALKEY_URL) return; // Skip in test try { const result = await valkey.ping(); if (result !== "PONG") { throw new Error(`Unexpected ping response: ${result}`); } } catch (error) { if (error instanceof Error) { throw new Error( `Fatal: Failed to connect to Valkey session cache. Halting boot. ${error.message}`, ); } throw new Error( `Fatal: Failed to connect to Valkey session cache. Halting boot.`, ); } }