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

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

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

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

[실습] Redis로 세션 스토리지 구축하기

JSCODE 박재성
JSCODE 박재성
2026-01-12
author
JSCODE 박재성
category
Redis
createdAt
Jan 12, 2026
series
비전공자도 이해할 수 있는 Redis 중급/실전
slug
build-session-storage-with-redis
type
post
updatedAt
Jan 12, 2026 12:17 AM
👨🏻‍🏫
Spring Boot에는 spring-session-data-redis라는 라이브러리가 있어서 Redis로 세션 스토리지를 쉽게 구축할 수 있다. 이 라이브러리를 활용해서 세션 스토리지를 구축해보자.

✅ 실습

  1. 의존성 추가하기
    1. build.gradle
      ... dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-webmvc' implementation 'org.springframework.boot:spring-boot-starter-data-redis' implementation 'org.springframework.session:spring-session-data-redis' compileOnly 'org.projectlombok:lombok' runtimeOnly 'com.mysql:mysql-connector-j' annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-data-jpa-test' testImplementation 'org.springframework.boot:spring-boot-starter-webmvc-test' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' } ...
      notion image
 
  1. application.yml 수정하기
    1. application.yml
      spring: datasource: url: jdbc:mysql://localhost:3306/mydb?rewriteBatchedInserts=true username: root password: password driver-class-name: com.mysql.cj.jdbc.Driver data: redis: host: localhost port: 6379 jpa: hibernate: ddl-auto: create show-sql: true session: store-type: redis
       
  1. RedisSessionConfig 파일 만들기
    1. Spring Boot에서 Redis 기반으로 세션 관리를 활성화하려면 아래 파일을 추가해주어야 한다.
      RedisSessionConfig
      @Configuration @EnableRedisHttpSession public class RedisSessionConfig { }
       
  1. Spring Boot 서버 두 대 띄우기
    1. 기존에 실행시켜놨던 Spring Boot 서버가 있다면 종료하고 아래 명령어를 입력하자.
      $ ./gradlew bootRun --args='--server.port=8080' $ ./gradlew bootRun --args='--server.port=8081'
       
  1. Postman으로 API 테스트해보기
    1. 8080번 포트로 로그인 API 요청 보내기
      1. notion image
         
    2. 8080번, 8081번 포트에서 사용자 정보 조회 API 요청 보내기
      1. notion image
        notion image
        8080번, 8081번 포트의 서버 둘 다에서 사용자 정보 조회 API가 잘 작동한다. Redis를 통해 세션 정보를 공유하고 있기 때문에 어떤 서버로 요청을 보내든 잘 작동하는 것이다.
       
  1. Redis에 세션 정보 저장됐는 지 확인하기
    1. $ keys * # key 값 확인하기 $ type [세션이 저장된 key] # type 확인하기 -> hash # (값이 깨져서 나올 것이다. 왜냐면 Spring Session이 세션 값을 Binary 형태로 Redis에 저장하기 때문이다.) $ HGETALL [세션이 저장된 key] # 해당 hash에 저장된 모든 field, value 불러오기 $ HGET [세션이 저장된 key] sessionAttr:userId $ HGET [세션이 저장된 key] sessionAttr:name
 
author
category
Redis
createdAt
Jan 12, 2026
series
비전공자도 이해할 수 있는 Redis 중급/실전
slug
type
series-footer
updatedAt
Jan 12, 2026 12:26 AM
📎
이 글은 비전공자도 이해할 수 있는 Redis 중급/실전 강의의 수업 자료 중 일부입니다.