ZCOUNT by score

Apply for Redis Developer Course Redis Regular Inspection / Technical Support Redis Enterprise Server

Count members in a score range

Usage: zcount key min max.
To count all members, use -inf for min and +inf for max.
min and max are inclusive.

Example

Command>zadd myzip  992 "Seoul" 342 "Busan" 246 "Daegu" 282 "Incheon" 151 "Gwangju" 1213 "Gyeonggi"
Result>6
Command>zadd myzip  150 "Gangwon" 206 "Chungnam" 264 "Gyeongbuk" 57 "Jeju"
Result>4
Command>zcount myzip -inf +inf   Number of all members in the set
Result> 10
Command>zcount myzip 300 +inf    Number of cities/provinces with population of 3 million or more
Result> 3
Command>zcount myzip 200 299    Number of cities/provinces with population between 2.00 and 2.99 million
Result> 4
Command>zcount myzip -inf 199    Number of cities/provinces with population of 1.99 million or less
Result> 3

View animation



Syntax

ZCOUNT key min max

  • Available since version 2.0.0.
  • Time complexity is O(log(N)). N is the number of members in the set.
Related commands ZCARD, RANGE, SCARD
Clients for Java Jedis, Lettuce, Redisson
Clients for C Hiredis

<< ZCARD ZCOUNT ZLEXCOUNT >>

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