SCARD · Valkey

SCARD

Returns the number of members in a set.

Usage

SCARD key

Description

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

Reply RESP2

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

Reply RESP3

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

Complexity

O(1)

ACL Categories

@fast @read @set

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

History

See also

SADD, SDIFF, SDIFFSTORE, SINTER, SINTERCARD, SINTERSTORE, SISMEMBER, SMEMBERS, SMISMEMBER, SMOVE, SPOP, SRANDMEMBER, SREM, SSCAN, SUNION, SUNIONSTORE.