import { RedisOptions } from 'ioredis';
import {
    getRedisHost,
    getRedisPassword,
    getRedisPort,
    isRedisTlsEnabled,
} from '../redis/redis.config';

/**
 * BullMQ requires maxRetriesPerRequest: null.
 * Uses the same Redis as the rest of the app.
 */
export function getBullMqRedisConnection(): RedisOptions {
    const host = getRedisHost();
    const useTls = isRedisTlsEnabled();

    return {
        host,
        port: getRedisPort(),
        password: getRedisPassword(),
        tls: useTls ? { servername: host } : undefined,
        family: 4,
        maxRetriesPerRequest: null,
    };
}
