zrangebyscore
ZRANGEBYSCORE
score로 범위를 지정해서 조회
사용법은 zrangebyscore key min max 이다.
min, max는 score의 범위이고, min, max 를 포함해서 조회한다.
모두 조회하려면 -inf, +inf를 사용한다.
score를 같이 보려면 withscores 옵션을 사용한다.
Example
명령> zadd mycom 2009 "Sun microsystems" 1992 Wang 2002 Netscape
결과> 3
명령> zadd mycom 1998 "Digital Equipment" 2002 K-mart 1987 "American motors"
결과> 3
명령> zrangebyscore mycom -inf +inf withscores
결과>
0) 1987 -> American motors
1) 1992 -> Wang
2) 1998 -> Digital Equipment
3) 2002 -> K-mart score가 같을 경우 member로 비교한다
4) 2002 -> Netscape
5) 2009 -> Sun microsystems
명령> zrangebyscore mycom 1998 2002 withscores
결과>
0) 1998 -> Digital Equipment
1) 2002 -> K-mart
2) 2002 -> Netscape
명령> zrangebyscore mycom 2005 +inf withscores
결과>
0) 2009 -> Sun microsystems
애니메이션 보기
포함하지 않게 하려면 min, max에 ( 를 사용
사용법은 zrangebyscore key (min (max 이다.
Example
명령> zrangebyscore mycom (1987 (2002 withscores
1987 < score < 2002
결과>
0) 1992 -> Wang
1) 1998 -> Digital Equipment
명령> zrangebyscore mycom (1998 2002 withscores
1998 < score <= 2002
결과>
0) 2002 -> K-mart
1) 2002 -> Netscape
애니메이션 보기
limit offset count 사용
사용법은 zrangebyscore key min max limit offset count 이다.
offset은 시작점을 나타내고, count는 조회할 member의 개수이다.
offset은 0부터 시작할 수 있고, count가 1 이상이여야 한다. 0 이면 조회되지 않는다.
limit가 있으면 offset count 모두 있어야 한다. 생략할 수 없다.
page 별 조회에 유용하게 사용할 수 있다.
Example
명령> zrangebyscore mycom -inf +inf withscores limit 0 3
결과>
0) 1987 -> American motors
1) 1992 -> Wang
2) 1998 -> Digital Equipment
명령> zrangebyscore mycom -inf +inf withscores limit 3 100
결과>
0) 2002 -> K-mart
1) 2002 -> Netscape
2) 2009 -> Sun microsystems
애니메이션 보기
명령문
ZRANGEBYSCORE key min max [withscores] [limit offset count]
- 이 명령은 version 1.2.0 부터 사용할 수 있습니다.
- Withscores 옵션은 version 2.0.0 부터 사용할 수 있습니다.
- 논리적 처리 소요시간은 O(log(N)+M)이다. N은 집합에 속한 member 개수이고,
M은 리턴될 member 개수입니다.
Clients for C
Hiredis