Redis - Set Scard Command


Advertisements

Redis SCARD command is used to return the number of elements stored in a set.

Return Value

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

Syntax

Following is the basic syntax of Redis SCARD command.

redis 127.0.0.1:6379> SCARD KEY_NAME

Example

redis 127.0.0.1:6379> SADD myset "hello" 
(integer) 1 
redis 127.0.0.1:6379> SADD myset "foo" 
(integer) 1 
redis 127.0.0.1:6379> SADD myset "hello" 
(integer) 0 
redis 127.0.0.1:6379> SCARD myset 
(integer) 2
redis_sets.htm
Advertisements