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.

SINTERCARD

Last updated
SINTERCARD numkeys key [key ...] [LIMIT limit]
Group
Set
Complexity
O(N*M) worst case, where N is the size of the smallest set and M is the number of sets
Arity
-3 (at least 3 words, counting the command name)
Flags
read-only
HotKV Cloud
All plans
On-Premise
no license needed

SINTERCARD returns how many members the intersection of the given sets would have, without building or returning it. With LIMIT, counting stops once limit common members are found, which is cheaper when you only need to know whether the intersection reaches a threshold. A missing key counts as an empty set, 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 numkeys should be greater than 0 if numkeys is not a positive integer.
  • ERR Number of keys can't be greater than number of args if fewer keys follow than numkeys says.
  • ERR LIMIT can't be negative if the limit is negative or not an integer.
  • ERR syntax error for anything else after the keys.
  • WRONGTYPE if any key holds a value that is not a set.
127.0.0.1:6379> SADD a "x" "y" "z"
(integer) 3
127.0.0.1:6379> SADD b "y" "z" "w"
(integer) 3
127.0.0.1:6379> SINTERCARD 2 a b
(integer) 2
127.0.0.1:6379> SINTERCARD 2 a b LIMIT 1
(integer) 1

Same as Redis 7.4 and Valkey 8.

SINTER, SCARD, ZINTERCARD