# ZINTERCARD

> Count the members of the intersection of sorted sets, optionally stopping at a limit.

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

```
ZINTERCARD numkeys key [key ...] [LIMIT limit]
```

- Group: Sorted set
- Complexity: O(N*K) worst case, where N is the smallest input and K the number of inputs
- HotKV Cloud: all plans
- On-Premise: no license needed

`ZINTERCARD` returns how many members the intersection of the given sorted
sets would have, without building or returning it. Inputs can also be plain
sets. With `LIMIT`, counting stops once `limit` common members are found. A
missing key counts as empty, so the result is `0`.

## Options

| Option | Effect |
| --- | --- |
| `numkeys` | How many keys follow. Must be at least 1. |
| `LIMIT limit` | Stop counting at `limit`. `0` (the default) means no limit. Can be repeated; the last one counts. |

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Success | Integer: the size of the intersection, capped at `limit` | Same |

Errors:

- `ERR value is not an integer or out of range` if `numkeys` is not an
  integer, and ``ERR at least 1 input key is needed for 'zintercard' command``
  if it is below 1.
- `ERR syntax error` if fewer keys follow than `numkeys` says, or anything
  other than `LIMIT limit` follows.
- `ERR LIMIT can't be negative` if the limit is negative or not an integer.
- `WRONGTYPE` if a key holds something other than a sorted set or a set.

## Examples

```
127.0.0.1:6379> ZADD q1 1 "a" 2 "b" 3 "c"
(integer) 3
127.0.0.1:6379> ZADD q2 1 "b" 2 "c" 3 "d"
(integer) 3
127.0.0.1:6379> ZINTERCARD 2 q1 q2
(integer) 2
127.0.0.1:6379> ZINTERCARD 2 q1 q2 LIMIT 1
(integer) 1
```

## Compatibility

Same as Redis 7.4 and Valkey 8.

## See also

[ZINTER](https://docs.hotkv.com/commands/zinter/index.md), [ZCARD](https://docs.hotkv.com/commands/zcard/index.md), [SINTERCARD](https://docs.hotkv.com/commands/sintercard/index.md)