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
- Arity
- -3 (at least 3 words, counting the command name)
- Flags
- read-only
- 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
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 value is not an integer or out of rangeifnumkeysis not an integer, andERR at least 1 input key is needed for 'zintercard' commandif it is below 1.ERR syntax errorif fewer keys follow thannumkeyssays, or anything other thanLIMIT limitfollows.ERR LIMIT can't be negativeif the limit is negative or not an integer.WRONGTYPEif a key holds something other than a sorted set or a set.
Examples
Section titled “Examples”127.0.0.1:6379> ZADD q1 1 "a" 2 "b" 3 "c"(integer) 3127.0.0.1:6379> ZADD q2 1 "b" 2 "c" 3 "d"(integer) 3127.0.0.1:6379> ZINTERCARD 2 q1 q2(integer) 2127.0.0.1:6379> ZINTERCARD 2 q1 q2 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.