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.

ZINTERCARD

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

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.
Case RESP2 RESP3
Success Integer: the size of the intersection, capped at limit Same

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 'zintercard' command if it is below 1.
  • ERR syntax error if fewer keys follow than numkeys says, or anything other than LIMIT limit follows.
  • ERR LIMIT can't be negative if the limit is negative or not an integer.
  • WRONGTYPE if a key holds something other than a sorted set or a set.
127.0.0.1:6379> ZADD q1 1 "a" 2 "b" 3 "c"
(integer) 3
127.0.0.1:6379> ZADD q2 1 "b" 2 "c" 3 "d"
(integer) 3
127.0.0.1:6379> ZINTERCARD 2 q1 q2
(integer) 2
127.0.0.1:6379> ZINTERCARD 2 q1 q2 LIMIT 1
(integer) 1

Same as Redis 7.4 and Valkey 8.

ZINTER, ZCARD, SINTERCARD