SINTERCARD
SINTERCARD numkeys key [key ...] [LIMIT limit]
- Group
- Set
- Complexity
- O(N*M) worst case, where N is the size of the smallest set and M is the number of sets
- Arity
- -3 (at least 3 words, counting the command name)
- Flags
- read-only
- HotKV Cloud
- All plans
- On-Premise
- no license needed
SINTERCARD returns how many members the intersection of the given sets
would have, without building or returning it. With LIMIT, counting stops
once limit common members are found, which is cheaper when you only need to
know whether the intersection reaches a threshold. A missing key counts as an
empty set, so the result is 0.
Options
Section titled “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
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
| Success | Integer: the size of the intersection, capped at limit |
Same |
Errors:
ERR numkeys should be greater than 0ifnumkeysis not a positive integer.ERR Number of keys can't be greater than number of argsif fewer keys follow thannumkeyssays.ERR LIMIT can't be negativeif the limit is negative or not an integer.ERR syntax errorfor anything else after the keys.WRONGTYPEif any key holds a value that is not a set.
Examples
Section titled “Examples”127.0.0.1:6379> SADD a "x" "y" "z"(integer) 3127.0.0.1:6379> SADD b "y" "z" "w"(integer) 3127.0.0.1:6379> SINTERCARD 2 a b(integer) 2127.0.0.1:6379> SINTERCARD 2 a b LIMIT 1(integer) 1Compatibility
Section titled “Compatibility”Same as Redis 7.4 and Valkey 8.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.