Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- docker
- InnerJoinMapOne
- vm ssh 포트 변경
- ssh 포트 변경
- 맥북개발환경
- nest login
- gcp ssh 포트 변경
- JWT
- macos개발환경
- ssh 연결 방법
- Nest.js 로그인
- docker mysql설치하기
- nest authentication
- How to Join Tables Without Relations in TypeORM
- jdk설치
- JWT쓰는이유
- jwt장점
- gcp ssh vm
- 패키지구조
- nest passport
- vm ssh 포트
- 도커로db설치
- nest jwt
- Nest.js login
- ssh연결
- 스프링부트패키지구조
- db로컬설치
- local database
- vm ssh port
- Nest.js
Archives
- Today
- Total
Seize the day
[Nest.js] CacheModule을 활용하여 Redis 연동 ( cache-manager-redis-store & tls 설정) 본문
개발/Node.js
[Nest.js] CacheModule을 활용하여 Redis 연동 ( cache-manager-redis-store & tls 설정)
nofunfromdev 2022. 5. 1. 19:21캐싱은 임시 데이터 저장소 역할을 한다.
먼저 필수 패키지를 설치한다.
$ npm install cache-manager
$ npm install -D @types/cache-manager
Nest는 cache-storage를 제공하는데 기본적으로는 in-memory이다. redis를 사용하기 위해 node-cache-manager-redis-store
를 설치한다.
npm install cache-manager-redis-store --save
ConfigModule
를 통해 환경변수를 불러온다.
import * as redisStore from 'cache-manager-redis-store';
import { ConfigModule, ConfigService } from "@nestjs/config";
import { CacheModule, Module } from '@nestjs/common';
@Module({
imports: [
CacheModule.registerAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
store: redisStore,
host: configService.get("REDIS_HOST"),
port: configService.get("REDIS_PORT"),
tls: {
host: configService.get("REDIS_HOST"),
rejectUnauthorized: false
},
auth_pass: configService.get("REDIS_AUTH_PASS"),
ttl: +configService.get("REDIS_TTL") || 60 * 60
}),
inject: [ConfigService],
})
]
})
export class AppModule {}
useFactory
에 들어가는 옵션을 찾기 힘들었다. node-cache-manager-redis-store
는 node-redis
를 사용하여 ts확인 후 위와 같이 적어줬다.
참고
반응형
'개발 > Node.js' 카테고리의 다른 글
Comments