Skip to content

ZCOUNT

ZCOUNT key min max

ZCOUNT counts the number of members in a sorted set between min and max (both inclusive)

If you want to use unbounded ranges, use -inf and +inf for min and max respectively. The command returns the count of members in a sorted set between min and max (both inclusive). Returns 0 if the key does not exist.

localhost:7379> ZADD k 10 k1
OK 1
localhost:7379> ZADD k 20 k2
OK 1
localhost:7379> ZADD k 30 k3
OK 1
localhost:7379> ZCOUNT k 10 20
OK 2
localhost:7379> ZCOUNT k 10 30
OK 3
localhost:7379> ZCOUNT k 10 40
OK 3
localhost:7379> ZCOUNT k 1 2
OK 0
localhost:7379> ZCOUNT k -inf +inf
OK 3
localhost:7379> ZCOUNT k 10 10
OK 1