What's new in Valkey 9.0? Discover new features and improvements. Read the announcement.

SCARD

Returns the number of members in a set.

Usage
SCARD key
Complexity
O(1)
Since
1.0.0
ACL Categories
@fast, @read, @set
Command flags
READONLY, FAST

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

Examples

127.0.0.1:6379> SADD myset "Hello"
(integer) 1
127.0.0.1:6379> SADD myset "World"
(integer) 1
127.0.0.1:6379> SCARD myset
(integer) 2

Replies

RESP2

Integer reply: the cardinality (number of elements) of the set, or 0 if the key does not exist.

RESP3

Integer reply: the cardinality (number of elements) of the set, or 0 if the key does not exist.