import { Global, Module } from "@nestjs/common";
import { ConfigModule, ConfigService } from "@nestjs/config";
import Redis from "ioredis";

@Global()
@Module({
  providers: [
    {
      provide: "REDIS",
      useFactory: (configService: ConfigService): Redis => {
        return new Redis({
          host: configService.get<string>('RD_HOST')!,
          port: configService.get<number>('RD_PORT')
        });
      },
      inject: [ConfigService]
    },
  ],
  exports: ["REDIS"]
})
export class RedisModule{}