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.

ZINTERSTORE

Last updated
ZINTERSTORE destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM | MIN | MAX]
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
-4 (at least 4 words, counting the command name)
Flags
write
Keys
first 1, last 1, step 1
HotKV Cloud
All plans
On-Premise
no license needed

ZINTERSTORE computes the same intersection as ZINTER and stores it as a sorted set at destination, replacing whatever was there. If the result is empty, destination is deleted. The inputs are read and the result written as one atomic step, and destination can also be one of the inputs.

Inputs can be sorted sets or plain sets (members score 1); a missing key makes the result empty.

Option Effect
numkeys How many keys follow. Must be at least 1.
WEIGHTS weight ... One multiplier per input key, applied before combining. Default 1 each.
AGGREGATE SUM | MIN | MAX How the scores of a member combine. Default SUM.

WITHSCORES is not accepted.

Case RESP2 RESP3
Success Integer: the number of members in the stored sorted set Same

Errors are those of ZINTER, with the command named zinterstore in the numkeys error; WITHSCORES gives ERR syntax error.

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> ZINTERSTORE both 2 q1 q2 WEIGHTS 2 1
(integer) 1
127.0.0.1:6379> ZSCORE both "bob"
"13"

Same as Redis 7.4 and Valkey 8.

ZINTER, ZUNIONSTORE, ZDIFFSTORE, SINTERSTORE