nestjs-redis icon indicating copy to clipboard operation
nestjs-redis copied to clipboard

Create a proper example with README how to add Redis module and consume it in application to listen to Redis client !!

Open tkssharma opened this issue 4 years ago • 1 comments

Please Create a proper example with README how to add Redis module and consume it in application to listen to Redis client !!

import { DynamicModule } from '@nestjs/common';
import { RedisModule, RedisModuleOptions} from 'nestjs-redis';
import { RedisConfigError } from '../database/db.error';
import { ConfigModule } from '../config/config.module';
import { ConfigService } from '../config/config.service';
export class CacheModule {
  public static getRedisOptions(config: ConfigService): RedisModuleOptions {
    const redisConfig = config.get().redis;
    if (!redisConfig) {
      throw new RedisConfigError('redis config is missing');
    }
    return redisConfig as RedisModuleOptions;
  }

  public static forRoot(): DynamicModule {
    return {
      module: CacheModule,
      imports: [
        RedisModule.forRootAsync({
          imports: [ConfigModule],
          useFactory: (configService: ConfigService) => CacheModule.getRedisOptions(configService),
          inject: [ConfigService]
      }),

      ],
      controllers: [],
      providers: [],
      exports: [],
    };
  }
}

Look like some dependancy is breaking when i am trying to create service and injecting that service in controllers where i have already added this redisModule in main module

tkssharma avatar Apr 19 '20 17:04 tkssharma

I would also be interested in this.

jacobdo2 avatar Jun 01 '20 09:06 jacobdo2