Spring Lists

레디스 개발자 교육 신청 레디스 정기점검/기술지원
Redis Technical Support
레디스 엔터프라이즈 서버
Redis Enterprise Server

Spring Lists

Java Spring Framework를 사용한 레디스 리스트(Lists) 명령 사용법입니다.


Lists 소스

Redis02_List.java


각 명령(메서드) 별 표시

LPUSH

RPOP

LPOP

RPUSH

LRANGE

LLEN

RPOPLPUSH


BLPOP

레디스 Lists에는 4개의 Blocking(대기) 명령이 있습니다. BLPOP/BRPOP/BRPOPLPUSH/BLMOVE
레터스(Lettuce)에서는 메서드명을 레디스 명령과 동일하게 해서 구분합니다.
스프링(Spring)에서는 메서드명은 일반 메서드명과 같이 사용하면서 인자로 대기 명령을 구분합니다.
예를 들어, leftPop(key)는 LPOP 명령이고 leftPop(key, long timeout, TimeUnit unit)는 BLPOP 명령입니다.
다음은 레디스 명령과 스프링 메서드 목록입니다.

BLPOP
    leftPop(key, long timeout, TimeUnit unit)
    leftPop(K key, Duration timeout)
BRPOP
    rightPop(K key, long timeout, TimeUnit unit)
    rightPop(K key, Duration timeout)
BRPOPLPUSH
    rightPopAndLeftPush(K sourceKey, K destinationKey, long timeout, TimeUnit unit)
    rightPopAndLeftPush(K sourceKey, K destinationKey, Duration timeout)
BLMOVE
    move(MoveFrom from, MoveTo to, Duration timeout)
    move(K sourceKey, Direction from, K destinationKey, Direction to, Duration timeout)
    move(K sourceKey, Direction from, K destinationKey, Direction to, long timeout, TimeUnit unit)

레터스와 스프링이 대기 명령을 처리하는 방식에는 다음과 같은 차이점이 있습니다.
레터스에서는 대기 명령을 한(같은) 연결(connection)에서 비동기로 실행합니다.
스프링에서는 대기 명령 실행마다 새로 연결(connection)을 맺어서 처리하고 끊습니다.
이것은 LettuceConnectionFactory 의 shareNativeConnection 설정과 관계없습니다.
새로 연결을 맺고 끊는데 따른 컴퓨터 자원 사용과 처리 시간을 고려하시기 바랍니다.

예제 8) BLPOP(leftPop) 메서드 실행
예제 9) connection 사용을 확인하기 위해서 리스트에 100개 데이터 입력
예제 10) BLPOP(leftPop) 메서드를 100번 반복 실행하면서 "redis-cli --stat"로 connection 확인


<< Strings Lists Sets >>

Email 답글이 올라오면 이메일로 알려드리겠습니다.

혹시 처음이세요?
레디스게이트에는 레디스에 대한 많은 정보가 있습니다.
레디스 소개, 명령어, SQL, 클라이언트, 서버, 센티널, 클러스터 등이 있습니다.
혹시 필요한 정보를 찾기 어려우시면 redisgate@gmail.com로 메일 주세요.
제가 찾아서 알려드리겠습니다.
 
close
IP를 기반으로 보여집니다.