JSCODE Logo
프로그래밍 과외블로그후기멘토진
회사명 : JSCODE대표 : 박재성사업자 등록번호 : 244-22-01557통신판매업 : 제 2023-인천미추홀-0381 호
학원 명칭 : 제이에스코드(JSCODE)원격학원학원설립ㆍ운영 등록번호 : 제6063호

서울특별시 구로구 경인로 20가길 11(오류동, 아델리아)

Copyright ⓒ 2025 JSCODE - 최상위 현업 개발자들의 프로그래밍 교육 All rights reserved.

이용약관개인정보처리방침
← 블로그 목록으로 돌아가기

[보충 설명] Nest.js가 v11일 경우 Redis 셋팅 방법

JSCODE 박재성
JSCODE 박재성
2025-12-06
author
JSCODE 박재성
category
Redis
createdAt
Dec 6, 2025
series
비전공자도 이해할 수 있는 Redis 입문/실전
slug
nestjs-v11-redis-setup
type
post
updatedAt
Dec 6, 2025 04:33 AM

✅ Nest.js 버전 확인 방법

Nest.js 프로젝트의 package.json 파일을 열어서 @nestjs/core가 몇 버전인지 확인하면 된다. 만약 아래와 같이 11.1.2라고 기재되어 있다면 Nest.js는 11 버전인 것이다.
package.json
{ ... "dependencies": { "@keyv/redis": "^4.4.0", "@nestjs/cache-manager": "^3.0.1", "@nestjs/common": "^11.1.2", "@nestjs/core": "^11.1.2", "@nestjs/platform-express": "^11.1.2", "@nestjs/typeorm": "^11.0.0", "cache-manager": "^6.4.3", "cache-manager-ioredis": "^2.1.0", "mysql2": "^3.14.1", "reflect-metadata": "^0.2.2", "rxjs": "^7.8.2", "typeorm": "^0.3.24" }, ... }
 
 

✅ Nest.js가 v11일 경우 Redis 셋팅 방법

  1. 의존성 설치
    1. $ npm install @keyv/redis
 
  1. app.module.ts 셋팅 변경
    1. import { Module } from "@nestjs/common"; import { TypeOrmModule } from "@nestjs/typeorm"; import { Board } from "./board.entity"; import { BoardController } from "./board.controller"; import { BoardService } from "./board.service"; import { CacheModule } from "@nestjs/cache-manager"; import KeyvRedis from "@keyv/redis"; @Module({ imports: [ TypeOrmModule.forRoot({ type: 'mysql', host: 'localhost', port: 3306, username: 'root', password: 'password123', database: 'mydb', autoLoadEntities: true, synchronize: true, }), TypeOrmModule.forFeature([Board]), CacheModule.registerAsync({ imports: undefined, useClass: undefined, useExisting: undefined, useFactory: async () => { return { stores: [ new KeyvRedis('redis://localhost:6379'), ] } } }), ], controllers: [BoardController], providers: [BoardService], }) export class AppModule {}
       
  1. Service 로직 수정
    1. @Injectable() export class BoardService { constructor( @InjectRepository(Board) private boardRepository: Repository<Board>, @Inject(CACHE_MANAGER) private cacheManager: Cache, ) {} async getBoards(page: number, size: number): Promise<Board[]> { const cacheKey = `boards:page:${page}:size:${size}`; const cachedData = await this.cacheManager.get<Board[]>(cacheKey); if (cachedData) { return cachedData; } const skip = (page - 1) * size; const boards = await this.boardRepository.find({ order: { createdAt: 'DESC' }, skip: skip, take: size, }); // ttl 값 추가 (단위 : milliseconds) await this.cacheManager.set(cacheKey, boards, 60 * 1000); return boards; } }
       
  1. Redis-cli를 활용해 정상적으로 캐싱이 됐는 지 확인하기
    1. $ redis-cli $ keys * # Redis에 저장되어 있는 모든 key 조회 $ get boards:page:1:size:10 # 특정 key의 Value 조회 $ ttl boards:page:1:size:10 # 특정 key의 TTL 조회
 
author
category
Redis
createdAt
series
비전공자도 이해할 수 있는 Redis 입문/실전
slug
type
series-footer
updatedAt
Dec 6, 2025 04:33 AM
📎
이 글은 비전공자도 이해할 수 있는 Redis 입문/실전 (조회 성능 최적화편) 강의의 수업 자료 중 일부입니다.