ZCOUNT command in redis

ZCOUNT key min max

This command counts the members in a sorted set with scores within the given values.

ZCOUNT command in redis returns the number of elements in the sorted set at the key with a score between min and max.

RETURN VALUE: 

Integer reply, the number of elements in the specified score range.

Syntax:

ZCOUNT KEY_NAME min max

Example 1: When  the key is present and min and max are in the range

redis:6379> ZADD mykey 1 A 2 B 3 C 4 D 5 E
(integer) 5
redis:6379> ZCOUNT mykey 1 3
(integer) 3

Output

3


Example 2: When  the key is not present or min and max are out of range

redis:6379> ZADD mykey 1 A 2 B 3 C 4 D 5 E
(integer) 5
redis:6379> ZCOUNT redisKey 1 3
(integer) 0
redis:6379> ZCOUNT mykey 10 20
(integer) 0

Output

0


No comments:

Post a Comment