| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 
 | import KeyvRedis, { Keyv } from '@keyv/redis';import { CacheModule } from '@nestjs/cache-manager';
 import { Module } from '@nestjs/common';
 import { ConfigModule, ConfigService } from '@nestjs/config';
 import { AppController } from './app.controller';
 import { AppService } from './app.service';
 import { environment } from './app.environment';
 
 const envFilePath = ['.env'];
 if (environment) envFilePath.unshift(`.env.${environment}`);
 
 
 @Module({
 imports: [
 ConfigModule.forRoot({
 isGlobal: true,
 envFilePath,
 }),
 CacheModule.registerAsync({
 isGlobal: true,
 imports: [ConfigModule],
 useFactory: async (cfg: ConfigService) => {
 const host = cfg.get<string>('REDIS_HOST') || '127.0.0.1';
 const port = cfg.get<number>('REDIS_PORT') || 6379;
 const database = cfg.get<number>('REDIS_DB') || 0;
 const redisOptions = {
 url: `redis://${host}:${port}/${database}`,
 };
 
 return {
 stores: [
 
 
 new Keyv({
 store: new KeyvRedis(redisOptions),
 namespace: 'test',
 useKeyPrefix: false,
 }),
 ],
 };
 },
 inject: [ConfigService],
 }),
 ],
 
 })
 export class AppModule {}
 
 |