Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

ZCARD

Last updated
ZCARD key
Group
Sorted set
Complexity
O(1)
Arity
2 (exactly, counting the command name)
Flags
read-only, fast
Keys
first 1, last 1, step 1
HotKV Cloud
All plans
On-Premise
no license needed

ZCARD returns the number of members (the cardinality) of the sorted set stored at key.

Case RESP2 RESP3
Sorted set exists Integer: the number of members Same
Key does not exist Integer 0 Same

ZCARD replies with a WRONGTYPE error if key holds a value that is not a sorted set.

127.0.0.1:6379> ZADD board 100 "alice" 90 "bob"
(integer) 2
127.0.0.1:6379> ZCARD board
(integer) 2

Same as Redis 7.4 and Valkey 8.

ZCOUNT, ZLEXCOUNT, ZADD