zrangebylex
ZRANGEBYLEX
![]() |
![]() Redis Technical Support |
![]() Redis Enterprise Server |
---|
member로 범위를 지정해서 조회
사용법은 zrangebylex key min max 이다.
min, max는 member의 범위이다. 모두 조회하려면 -, +를 사용한다.
min, max에 값을 줄 경우 반드시 앞에 [ 또는 ( 를 사용해야 한다.
[ 는 값을 포함할 때 사용하고, ( 는 제외할 때 사용한다.
이 명령은 score가 모두 같아야 원하는 결과를 얻을 수 있다.
이 명령에는 withscores 옵션이 없다.
Example
명령> | zrangebylex city - + |
결과> |
0) Beijing 1) New Delhi 2) New York 3) Seoul |
명령> | zrangebylex city "[New Delhi" + |
결과> |
0) New Delhi 1) New York 2) Seoul |
명령> | zrangebylex city "(New Delhi" + |
결과> |
0) New York 1) Seoul |
명령> | zrangebylex city "(New Delhi" "(Seoul" |
결과> |
0) New York |
limit offset count 사용
사용법은 zrangebylex key min max limit offset count 이다.
offset은 시작점을 나타내고, count는 조회할 member의 개수이다.
offset은 0부터 시작할 수 있고, count가 1 이상이여야 한다. 0 이면 조회되지 않는다.
limit가 있으면 offset count 모두 있어야 한다.
page 별 조회에 유용하게 사용할 수 있다.<
Example
명령> | zrangebylex city - + limit 0 2 |
결과> |
0) Beijing 1) New Delhi |
명령> | zrangebylex city - + limit 2 2 |
결과> |
0) New York 1) Seoul |
JOIN(조인) 기능
JOIN(조인)은 ZSet key1의 멤버와 다른 ZSet key2의 멤버를 조인해서 key1의 value, score와
key2의 score를 한번에 조회합니다.
예) 글(포스트) 관리: post-id 순으로 조회할 때 사용
post-id 키에 멤버 post-100, post-101, post-102, 스코어는 0을 넣는다.
post-view 키에 조회수,
post-good 키에 좋아요수, post-bad에 싫어요수를 넣는다.
ZADD post-id 0 post-100 0 post-101 0 post-103
ZADD post-view 100 post-100 101 post-101 102 post-102
ZADD post-good 70 post-100 71 post-101 72 post-102
ZADD post-bad 20 post-100 21 post-101 22 post-102
Example
명령> | zrangebylex post-id - + JOIN post-view JOIN post-good JOIN post-bad table |
결과> |
0) "post-id" "post-view" "post-good" "post-bad" 1) "post-100" "100" "70" "20" 2) "post-101" "101" "71" "21" 3) "post-102" "102" "72" "22" |
조인 기능은 Enterprise 서버에서 사용 가능합니다. |
Hash 키와 조인
Hash 키에 post-id 별로 userid, title, content를 저장한다.
hset post-100 userid user-100 title Title-A content content-A
hset post-101 userid user-101 title Title-B content content-B
hset post-102 userid user-102 title Title-C content content-C
Example
명령> | zrangebylex post-id - +
JOIN post-view JOIN post-good JOIN post-bad JOIN hmget * userid title content table |
결과> |
0) "post-id" "post-view" "post-good" "post-bad" "userid" "title" "content" 1) "post-100" "100" "70" "20" "user-100" "Title-A" "Content-A" 2) "post-101" "101" "71" "21" "user-101" "Title-B" "Content-B" 3) "post-102" "102" "72" "22" "user-102" "Title-C" "Content-C" |
String 키와 조인
String 키에 user-id 별로 user 정보를 저장한다.
set user-100 "Kim,kim@naver.com"
set user-101 "Yun,yun@naver.com"
set user-102 "Tae,tae@naver.com"
Example
명령> | zrangebylex post-view - +
JOIN post-view JOIN post-good JOIN post-bad JOIN hmget * userid title content JOIN get userid table |
결과> |
0) "post-id" "post-view" "post-good" "post-bad" "userid" "title" "content" "userid" 1) "post-100" "100" "70" "20" "user-100" "Title-A" "Content-A" "Kim,kim@naver.com" 2) "post-101" "101" "71" "21" "user-101" "Title-B" "Content-B" "Yun,yun@naver.com" 3) "post-102" "102" "72" "22" "user-102" "Title-C" "Content-C" "Tae,tae@naver.com" |
명령문
ZRANGEBYLEX key min max [limit offset count] [JOIN zset-key JOIN hmget * field1 field2 JOIN get field1]
- 이 명령은 version 2.8.9 부터 사용할 수 있습니다.
- JOIN은 Enterprise version에서 사용할 수 있습니다.
- 논리적 처리 소요시간은 O(log(N)+M)이다. N은 집합에 속한 member 개수이고, M은 리턴될 member 개수입니다.
관련 명령 | ZRANGE, ZREVRANGE, ZREVRANGEBYSCORE, LRANGE |
Clients for Java | Jedis, Lettuce, Redisson | Clients for C | Hiredis |
<< ZREVRANGEBYSCORE | ZRANGEBYLEX | ZREVRANGEBYLEX >> |
---|