"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRedisClient = exports.connectRedis = exports.redisClient = void 0;
const redis_1 = require("redis");
const logger_1 = require("./logger");
const redisUrl = process.env.REDIS_URL || 'redis://localhost:6379';
exports.redisClient = (0, redis_1.createClient)({
    url: redisUrl,
    socket: {
        connectTimeout: 5000,
        reconnectStrategy: (retries) => {
            if (retries > 3) {
                logger_1.logger.warn('⚠️ Max Redis reconnect attempts reached. Operating in memory fallback mode.');
                return new Error('Redis max retries reached');
            }
            return Math.min(retries * 100, 3000);
        },
    },
});
exports.redisClient.on('error', (err) => {
    logger_1.logger.warn(`Redis Client Warning/Error: ${err.message}`);
});
exports.redisClient.on('connect', () => {
    logger_1.logger.info('🔴 Redis client connected successfully');
});
const connectRedis = async () => {
    try {
        await exports.redisClient.connect();
    }
    catch (error) {
        logger_1.logger.warn(`⚠️ Redis connection could not be established immediately: ${error.message}. Service will fallback gracefully.`);
    }
};
exports.connectRedis = connectRedis;
const getRedisClient = () => exports.redisClient;
exports.getRedisClient = getRedisClient;
//# sourceMappingURL=redis.js.map