import Redis from "ioredis";

declare global {
  // eslint-disable-next-line no-var
  var __redis: Redis | undefined;
}

export function getRedis(): Redis {
  if (!globalThis.__redis) {
    globalThis.__redis = new Redis(
      process.env["REDIS_URL"] ?? "redis://localhost:6379",
      { lazyConnect: false, maxRetriesPerRequest: 3 }
    );
  }
  return globalThis.__redis;
}
