ZCARD

Since 1.1.0Sorted sets

Syntax

ZCARD key
  • Flags: fast, readonly
  • ACL categories: @fast, @read, @sortedset
  • Arity: 2

Returns the number of members of the sorted set at key: the size of a leaderboard, or of a queue kept as a sorted set. To count only the members in a range, use ZCOUNT for a range of scores or ZLEXCOUNT for a range of members.

A key that does not exist counts as an empty sorted set, so the reply is 0, not an error. A sorted set whose last member is removed is deleted, so an existing sorted set never has 0 members.

Reply

  • The number of members.
  • 0 if the key does not exist.

Errors

  • WRONGTYPE Operation against a key holding the wrong kind of value if the key holds something other than a sorted set.

Examples

> ZADD z 1 a 2 b 3 c
(integer) 3
> ZCARD z
(integer) 3
> ZCARD missing
(integer) 0
> SET s x
OK
> ZCARD s
(error) WRONGTYPE Operation against a key holding the wrong kind of value