본문 바로가기

카테고리 없음

[Redis] 레디스 클라이언트 Lettuce vs Jedis

 

 

Spring Boot에서 Redis를 사용할 때 대표적인 두 가지 Redis 클라이언트는 Lettuce와 Jedis입니다.

  • Lettuce는 비동기와 고성능에 적합하고, 스프링 공식 지원 기본 클라이언트입니다.
  • Jedis는 구조가 간단하고 직관적이지만, 스레드 세이프하지 않아 멀티스레드 환경에서는 주의가 필요합니다.

 

1. Lettuce vs Jedis 요약 비교

항목 Lettuce Jedis
기반 네트워크 모델 비동기, 넌블로킹 (Netty 기반) 동기, 블로킹 (자바 Socket 기반)
스레드 안전성 스레드 세이프 (싱글 인스턴스 공유 가능) 스레드 세이프 아님 (스레드마다 Jedis 인스턴스 필요)
Spring Boot 기본 클라이언트 기본 (Spring Boot 2.0 이상) 수동 설정 필요
성능 높은 동시성에 강함 (비동기 처리 가능) 적은 동시성에 적합 (간단한 구조)
Pub/Sub 지원 지원
커넥션 풀 기본적으로 지원 (non-blocking) 직접 설정 필요 (blocking 방식)
사용 편의성 약간 복잡 (reactive, async 구조 대응) 단순하고 직관적

 

 

2. 상황 별 추천 클라이언트

상황 추천 클라이언트
단순한 캐싱 또는 세션 저장용 Jedis (간단한 구조에 유리)
WebFlux, 비동기 환경 (Reactive Web) Lettuce (Netty 기반, async/reactive 지원)
높은 TPS, 대규모 사용자 처리 Lettuce (비동기/논블로킹 처리로 성능 우수)
쓰레드 풀 관리 없이 간단하게 사용 Jedis (단, 스레드마다 인스턴스 생성 필요 주의)

 

 

3. Spring Boot 적용 예시

1) Lettuce(기본)

// build.gradle
implementation 'org.springframework.boot:spring-boot-starter-data-redis'

 

# application.properties

# Redis 기본 설정
spring.redis.host=localhost
spring.redis.port=6379

# Lettuce 커넥션 풀 설정
spring.redis.lettuce.pool.max-active=10
spring.redis.lettuce.pool.max-idle=5
spring.redis.lettuce.pool.min-idle=1
spring.redis.lettuce.shutdown-timeout=100ms

 

2) Jedis(직접 지정 필요)

// build.gradle
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'redis.clients:jedis'

 

# application.properties

# Redis 기본 설정
spring.redis.host=localhost
spring.redis.port=6379

# Jedis 클라이언트 사용 명시
spring.redis.client-type=jedis

# Jedis 커넥션 풀 설정
spring.redis.jedis.pool.max-active=10
spring.redis.jedis.pool.max-idle=5
spring.redis.jedis.pool.min-idle=1