All files / config redis.js

0% Statements 0/21
0% Branches 0/4
0% Functions 0/6
0% Lines 0/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34                                                                   
const redis = require('redis');
const logger = require('../utils/logger');
require('dotenv').config();
 
const client = redis.createClient({
  url: process.env.REDIS_URL || 'redis://localhost:6379',
  socket: {
    reconnectStrategy: (retries) => {
      if (retries > 10) {
        logger.error('Redis max reconnection attempts reached');
        return new Error('Redis max reconnection attempts reached');
      }
      return retries * 100;
    }
  }
});
 
client.on('error', (err) => logger.error('Redis Client Error', err));
client.on('connect', () => logger.info('Redis Client Connected'));
client.on('reconnecting', () => logger.info('Redis Client Reconnecting'));
client.on('ready', () => logger.info('Redis Client Ready'));
 
// Connect to Redis
(async () => {
  try {
    await client.connect();
  } catch (error) {
    logger.error('Failed to connect to Redis:', error);
  }
})();
 
module.exports = client;