Skip to content

Instantly share code, notes, and snippets.

@airscholar
Created July 22, 2022 19:03
Show Gist options
  • Save airscholar/4238947490a3dfd09fb05f5fda2b06cc to your computer and use it in GitHub Desktop.
Save airscholar/4238947490a3dfd09fb05f5fda2b06cc to your computer and use it in GitHub Desktop.
import { Module, CacheModule } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import * as redisStore from 'cache-manager-redis-store';
import { RedisCacheService } from './redis-cache.service';
@Module({
imports: [
CacheModule.registerAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: async (configService: ConfigService) => ({
store: redisStore,
host: configService.get<string>('REDIS_USERNAME'),
username: configService.get<string>('REDIS_USERNAME'),
password: configService.get<string>('REDIS_PASSWORD'),
port: configService.get<number>('REDIS_PORT'),
ttl: configService.get('REDIS_TTL'),
}),
isGlobal: true,
}),
],
providers: [RedisCacheService],
})
export class RedisCacheModule {}
import { Injectable } from '@nestjs/common';
@Injectable()
export class RedisCacheService {
// extendable redis cache service goes here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment