# ZCARD

> Get the number of members in a sorted set.

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

```
ZCARD key
```

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

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

## Return value

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

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

## Examples

```
127.0.0.1:6379> ZADD board 100 "alice" 90 "bob"
(integer) 2
127.0.0.1:6379> ZCARD board
(integer) 2
```

## Compatibility

Same as Redis 7.4 and Valkey 8.

## See also

[ZCOUNT](https://docs.hotkv.com/commands/zcount/index.md), [ZLEXCOUNT](https://docs.hotkv.com/commands/zlexcount/index.md), [ZADD](https://docs.hotkv.com/commands/zadd/index.md)