ZINTER
ZINTER numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM | MIN | MAX] [WITHSCORES]
- Group
- Sorted set
- Complexity
- O(N*K)+O(M*log(M)) worst case, where N is the smallest input, K the number of inputs and M the size of the result
- Arity
- -3 (at least 3 words, counting the command name)
- Flags
- read-only
- HotKV Cloud
- All plans
- On-Premise
- no license needed
ZINTER returns the members that appear in every one of the given sorted
sets, ordered by their combined score. A member’s combined score is built from
its score in each input, by default by adding them up.
Inputs can also be plain sets; their members count as having score 1. A
missing key counts as empty, so the result is empty. To store the result
instead, use ZINTERSTORE; to count it, use
ZINTERCARD.
Options
Section titled “Options”| Option | Effect |
|---|---|
numkeys |
How many keys follow. Must be at least 1. |
WEIGHTS weight ... |
One multiplier per input key, applied to that input’s scores before they are combined. Default 1 each. |
AGGREGATE SUM |
Add up the (weighted) scores. The default. |
AGGREGATE MIN |
Keep the lowest (weighted) score. |
AGGREGATE MAX |
Keep the highest (weighted) score. |
WITHSCORES |
Return each member with its combined score. Must be the last argument. |
Return value
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
| Success | Array of members | Same |
With WITHSCORES |
Flat array: member, score, … (scores as bulk strings) | Array of [member, score] pairs, the score a double |
Errors:
ERR value is not an integer or out of rangeifnumkeysis not an integer, andERR at least 1 input key is needed for 'zinter' commandif it is below 1.ERR syntax errorif fewer keys follow thannumkeyssays,WEIGHTShas too few values, theAGGREGATEvalue is unknown, or anything else follows.ERR weight value is not a floatfor a weight that is not a number.WRONGTYPEif a key holds something other than a sorted set or a set. Key types are checked before the options.
Examples
Section titled “Examples”127.0.0.1:6379> ZADD q1 10 "alice" 5 "bob"(integer) 2127.0.0.1:6379> ZADD q2 3 "bob" 7 "carol"(integer) 2127.0.0.1:6379> ZINTER 2 q1 q2 WITHSCORES1) "bob"2) "8"127.0.0.1:6379> ZINTER 2 q1 q2 AGGREGATE MIN WITHSCORES1) "bob"2) "3"Compatibility
Section titled “Compatibility”Same replies as Redis 7.4 and Valkey 8. HotKV requires WITHSCORES to be the
last argument; Redis and Valkey also accept it before WEIGHTS or
AGGREGATE.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.