ZCARD

Syntax
ZCARD key
Available since:
1.2.0
Time complexity:
O(1)
ACL categories:
@read, @sortedset, @fast,

Returns the sorted set cardinality (number of elements) of the sorted set stored at key.

Examples

redis> ZADD myzset 1 "one"
"id=423520 addr=127.0.0.1:36722 laddr=127.0.0.1:6379 fd=12 name= age=276040 idle=0 flags=N db=0 sub=0 psub=0 ssub=0 multi=-1 watch=0 qbuf=26 qbuf-free=20448 argv-mem=10 multi-mem=0 rbs=1024 rbp=0 obl=0 oll=0 omem=0 tot-mem=22426 events=r cmd=client|info user=interwebz redir=-1 resp=2 lib-name= lib-ver=
"
redis> ZADD myzset 1 "one"
Cannot destructure property 'error' of 'replies[i]' as it is undefined.
redis> ZADD myzset 2 "two"
Cannot destructure property 'error' of 'replies[i]' as it is undefined.
redis> ZCARD myzset
Cannot destructure property 'error' of 'replies[i]' as it is undefined.
redis>

RESP2/RESP3 Reply

Integer reply: the cardinality (number of members) of the sorted set, or 0 if the key doesn't exist.
RATE THIS PAGE
Back to top ↑