ZCARD command in redis

ZCARD key

Return the sorted set cardinality (number of elements). If the key does not exist 0 is returned, like for empty sorted sets.

TIME COMPLEXITY: O(1)

RETURN VALUE: Integer reply, specifically:

the cardinality (number of elements) of the set as an integer. 

Syntax:

ZCARD key

Example 1: When the key is present

redis:6379> ZADD key 10.9 member
(integer) 1
redis:6379> ZCARD key
(integer) 1

Output

1


Example 2: When the key is not present

redis:6379> ZCARD key1
(integer) 0

Output

0


No comments:

Post a Comment