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:
@@ -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
|
||||||
await redisClient.connect();
|
if (process.env.NODE_ENV !== 'test') {
|
||||||
|
await redisClient.connect();
|
||||||
|
}
|
||||||
|
|
||||||
export default redisClient;
|
export default redisClient;
|
||||||
|
|||||||
Reference in New Issue
Block a user