// Packages
import Redis from "ioredis";

// Config
import { appConfig } from "$config/index.js";
import { databaseConfig } from "$config/index.js";

const { redisConfig } = databaseConfig;

// Redis configuration
let config = {
  host: redisConfig.host || "localhost",
  port: redisConfig.port || 6379,
  db: redisConfig.db || 0,
};
if (appConfig.environment === "production") {
  config = {
    path: redisConfig.path || undefined,
  };
}

// Create Redis client instance
const redis = new Redis(config);

export default redis;
