Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

ZINTER

Last updated
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.

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.
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 range if numkeys is not an integer, and ERR at least 1 input key is needed for 'zinter' command if it is below 1.
  • ERR syntax error if fewer keys follow than numkeys says, WEIGHTS has too few values, the AGGREGATE value is unknown, or anything else follows.
  • ERR weight value is not a float for a weight that is not a number.
  • WRONGTYPE if a key holds something other than a sorted set or a set. Key types are checked before the options.
127.0.0.1:6379> ZADD q1 10 "alice" 5 "bob"
(integer) 2
127.0.0.1:6379> ZADD q2 3 "bob" 7 "carol"
(integer) 2
127.0.0.1:6379> ZINTER 2 q1 q2 WITHSCORES
1) "bob"
2) "8"
127.0.0.1:6379> ZINTER 2 q1 q2 AGGREGATE MIN WITHSCORES
1) "bob"
2) "3"

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.

ZINTERSTORE, ZINTERCARD, ZUNION, SINTER