import { Redis } from "ioredis";
export * from "ioredis";

let redis: Redis | undefined;

let defaultRedisUrl = process.env.REDIS_URL ?? "";

export function getRedisInstance(url: string = defaultRedisUrl) {
  if (redis) {
    return redis;
  }
  redis = new Redis(url, {
    lazyConnect: true,
    connectTimeout: 5000,
    commandTimeout: 5000,
  });
  return redis;
}
