npm i @webeleon/nestjs-redis
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { RedisModule } from '@webeleon/nestjs-redis';
import { redisConfig } from './configurations/redis.config';
@Module({
imports: [
RedisModule.forRoot({
url: 'redis://localhost:6379',
}),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { RedisModule } from '@webeleon/nestjs-redis';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { redisConfig } from './configurations/redis.config';
@Module({
imports: [
ConfigModule.forRoot({
load: [redisConfig],
}),
RedisModule.forRootAsync({
useFactory: async (configService) => configService.get('redis'),
inject: [ConfigService]
}),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
Import the RedisModule.forFeature()
inside a feature module.
import { RedisModule } from './redis.module';
@Module({
imports: [
RedisModule.forFeature()
]
})
class SomeModule {}
Then you'll be able to inject the RedisClient inside any provider.
import { Injectable } from '@nestjs/common';
import { InjectRedisClient, RedisClient } from '@webeleon/nestjs-redis';
@Injectable()
export class SomeService {
constructor(
@InjectRedisClient() redisClient: RedisClient
) {}
}
npm run generate-doc