Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tkssharma opened this issue Apr 19, 2020 · 1 comment

Comments

@tkssharma
Copy link

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

@jacobdo2
Copy link

jacobdo2 commented Jun 1, 2020

I would also be interested in this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants