Hello, I have an issue with these lines of code. try { const redisClient = new Redis({ host: process.env.REDIS_HOST, port: process.env.REDIS_PORT, }); const pingResult = await redisClient.ping(); if (pingResult === "PONG") { healthStatus.redis = "OK"; } else { healthStatus.redis = "DOWN"; } } catch (error) { healthStatus.redis = "DOWN"; overallHealthStatus = 503; console.log("Error connecting to Redis:>>>>>>", error); } I noticed this line throwing an error const pingResult = await redisClient.ping(); The error is "MaxRetriesPerRequestError: Reached the max retries per request limit (which is 20). Refer to "maxRetriesPerRequest" option for details". How do I fix this?
@codewithsoumyajeet841718 күн бұрын
Try these solutions. 1. Make sure you are able to read the env variables. Do console log on process.env.REDIS_HOST and see if you are seeing values. Try like this const redisClient = new Redis({ host: process.env.REDIS_HOST || 'localhost', port: process.env.REDIS_PORT || 6379, }); 2. Remove any quote mark in .env file REDIS_HOST=localhost REDIS_PORT=6379 3. Make sure the function is async function 4. Remove the mongo and rabbitmq and test the redis connection in isolation. 5. Check redis connection status. see if you are connecting before initialization redisClient.on('error', (err) => { console.log('Redis error event:', err); }); redisClient.on('connect', () => { console.log('Connected to Redis'); }); redisClient.on('ready', () => { console.log('Redis is ready'); });