Created
July 22, 2022 19:03
-
-
Save airscholar/4238947490a3dfd09fb05f5fda2b06cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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