Enhance Redis client connection logic to skip connection if REDIS_URL is not set, with a warning message for clarity.

This commit is contained in:
Luke Hagar
2025-08-14 13:15:33 -05:00
parent 51c86ba002
commit 8a19a483e4

View File

@@ -6,10 +6,19 @@ let isConnecting = false;
let isDisconnecting = false;
export function getRedisClient() {
const redisUrl = process.env.REDIS_URL;
// Skip connecting if no REDIS_URL is provided (e.g., during build)
if (!redisUrl) {
if (typeof process !== 'undefined') {
console.warn('Redis disabled: REDIS_URL not set');
}
return null;
}
if (!redisClient && !isConnecting) {
isConnecting = true;
redisClient = createClient({
url: process.env.REDIS_URL || 'redis://localhost:6379',
url: redisUrl,
});
redisClient.on('error', (err) => {