Redis command - ordered collection - zcount

 

original

http://redis.io/commands/zcount

 

Introduction

Count the members in a sorted set with scores within the given values.

 

Counts the number of elements in a sorted set whose scores fall within a specified range of values.

 

grammar

ZCOUNT key min max

 

Version

Available since 2.0.0.

 

Available since version 2.0.0.

 

time complexity

Time complexity: O(log(N)) with N being the number of elements in the sorted set.

 

O(log(N)): N is the number of elements in the sorted set.

 

describe

Returns the number of elements in the sorted set at key with a score between min and max.

 

Returns the number of elements in the sorted set with scores between min and max.

 

The min and max arguments have the same semantic as described for ZRANGEBYSCORE.

 

The parameters min and max have the same semantics as the ZRANGEBYSCORE command.

 

Note: the command has a complexity of just O(log(N)) because it uses elements ranks (see ZRANK) to get an idea of the range. Because of this there is no need to do a work proportional to the size of the range.

 

return value

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

 

Integer: Specifies the number of elements in the fractional range.

 

example

redis>  ZADD myzset 1 "one"
(integer) 1
redis>  ZADD myzset 2 "two"
(integer) 1
redis>  ZADD myzset 3 "three"
(integer) 1
redis>  ZCOUNT myzset -inf +inf
(integer) 3
redis>  ZCOUNT myzset (1 3
(integer) 2
redis>

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327006250&siteId=291194637