Redis Set SCARD Command
The Redis SCARD command returns the set cardinality (number of elements) of the set stored at key.
Syntax
The basic syntax of the SCARD command is as follows:
1 | SCARD key |
Available Since
Redis version >= 1.0.0
Time Complexity
O(1)
ACL Categories
@read, @set, @fast
Return Value
Returns the cardinality (number of elements) of the set, or 0 if the key does not exist.
Example 1
1 | 127.0.0.1:6379> SADD s_db redis |
Example 2
If the key does not exist, it returns 0.
1 | 127.0.0.1:6379> EXISTS ss |
In the example above, we first check if the key(ss) exists. If it doesn’t, the EXISTS command returns 0. Next, we execute the SCARD command, which also returns 0.
All articles on this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated.


