fix: skip Redis connection in test mode — prevents CI hang

The top-level await redisClient.connect() in redis-client.js was
blocking module import when no Redis server is available (CI env).
Add NODE_ENV guard + reconnect strategy with max retries.
This commit is contained in:
Antoni Nuñez Romeu
2026-07-14 13:03:46 +02:00
parent 3bfc0524d5
commit d66a9184aa
+8 -2
View File
@@ -4,7 +4,11 @@ import { createClient } from 'redis';
const redisClient = createClient({ const redisClient = createClient({
socket: { socket: {
host: process.env.REDIS_HOST || 'localhost', host: process.env.REDIS_HOST || 'localhost',
port: process.env.REDIS_PORT || 6379 port: process.env.REDIS_PORT || 6379,
reconnectStrategy: (retries) => {
if (retries > 10) return new Error('Redis max retries reached');
return Math.min(retries * 100, 3000);
}
}, },
password: process.env.REDIS_PASSWORD || undefined password: process.env.REDIS_PASSWORD || undefined
}); });
@@ -19,7 +23,9 @@ redisClient.on('connect', () => {
console.log('✅ Connected to Redis'); console.log('✅ Connected to Redis');
}); });
// Connect to Redis // Connect to Redis — skip in test (services are mocked) or when REDIS_URL is unset
if (process.env.NODE_ENV !== 'test') {
await redisClient.connect(); await redisClient.connect();
}
export default redisClient; export default redisClient;