# SCARD

> Get the number of members in a set.

URL: https://docs.hotkv.com/commands/scard/

```
SCARD key
```

- Group: Set
- Complexity: O(1)
- HotKV Cloud: all plans
- On-Premise: no license needed

`SCARD` returns the number of members (the cardinality) of the set stored at
`key`.

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Set exists | Integer: the number of members | Same |
| Key does not exist | Integer `0` | Same |

`SCARD` replies with a `WRONGTYPE` error if `key` holds a value that is not a
set.

## Examples

```
127.0.0.1:6379> SADD tags "redis" "cache" "db"
(integer) 3
127.0.0.1:6379> SCARD tags
(integer) 3
127.0.0.1:6379> SCARD nosuchkey
(integer) 0
```

## Compatibility

Same as Redis 7.4 and Valkey 8.

## See also

[SMEMBERS](https://docs.hotkv.com/commands/smembers/index.md), [SINTERCARD](https://docs.hotkv.com/commands/sintercard/index.md), [SADD](https://docs.hotkv.com/commands/sadd/index.md)