SINTERCARD(3valkey)
π SINTERCARD β the "how many of us are in the group chat" counter π
okay bestie, welcome to the Valkey Command Manual page for SINTERCARD(3valkey). yes it's a manual page, no it does not have to be boring, sit down, hydrate, let's go π«Ά
β¨ NAME β¨
sintercard β returns the number of members of the intersect of multiple sets. literally just the count, not the whole set. the vibe is "how many besties showed up", not "who showed up" π
β¨ SYNOPSIS β¨
SINTERCARD numkeys key [key...] [LIMIT limit]
β¨ DESCRIPTION β¨
so this command is basically SINTER's cooler, more low-key sibling. same intersection energy, but instead of handing you back the whole result set, it just tells you the cardinality of the result. that means: the cardinality of the set you'd get from intersecting all the sets you passed in. no cap β¨
here's the thing about keys that don't exist β they're just treated as empty sets, periodt. and if even one of your keys is an empty set, the whole resulting set is empty too (because intersecting anything with an empty set always gives you an empty set β math said so, and math ate π).
by default, the command just computes the cardinality of the intersection of all the sets you gave it. but when you pass the optional LIMIT argument (which defaults to 0, and 0 means unlimited, iykyk), something cute happens: if the intersection cardinality reaches limit partway through the computation, the algorithm just exits early and yields limit as the cardinality. it's giving "we already hit the number, why keep counting". this implementation guarantees a significant speedup for queries where the limit is lower than the actual intersection cardinality. slay π₯
β¨ REPLY β¨
valkey-protocol(7) Integer reply: the number of elements in the resulting intersection. just a number bestie, a plain little integer π
β¨ COMPLEXITY β¨
O(N*M) worst case, where N is the cardinality of the smallest set and M is the number of sets. so likeβ¦ don't throw 400 sets at it and then act surprised π
β¨ ACL CATEGORIES β¨
@read@set@slow
β¨ HISTORY β¨
- Available since:
7.0.0β (a modern icon, honestly)
β¨ EXAMPLES β¨
watch me set up two little sets and then count the overlap π
127.0.0.1:6379> SADD key1 "a"
(integer) 1
127.0.0.1:6379> SADD key1 "b"
(integer) 1
127.0.0.1:6379> SADD key1 "c"
(integer) 1
127.0.0.1:6379> SADD key1 "d"
(integer) 1
127.0.0.1:6379> SADD key2 "c"
(integer) 1
127.0.0.1:6379> SADD key2 "d"
(integer) 1
127.0.0.1:6379> SADD key2 "e"
(integer) 1
127.0.0.1:6379> SINTER key1 key2
1) "c"
2) "d"
127.0.0.1:6379> SINTERCARD 2 key1 key2
(integer) 2
127.0.0.1:6379> SINTERCARD 2 key1 key2 LIMIT 1
(integer) 1
see how SINTER gave us the whole little squad ("c" and "d"), but SINTERCARD just said "2" and kept it moving? and then with LIMIT 1 it stopped as soon as it hit one. main character energy, honestly π
β¨ SEE ALSO β¨
sadd(3valkey), scard(3valkey), sdiff(3valkey), sdiffstore(3valkey), sinter(3valkey), sinterstore(3valkey), sismember(3valkey), smembers(3valkey), smismember(3valkey), smove(3valkey), spop(3valkey), srandmember(3valkey), srem(3valkey), sscan(3valkey), sunion(3valkey), sunionstore(3valkey) π¦
ngl this whole set family is iconic, go read them all, they're all in the 3valkey section, you're welcome π
okay that's the page!! πΈ this one's from Valkey 9.0.0, dated 2025-10-21, and yeah the original page header/footer both said SINTERCARD(3valkey) like three times because manpages are dramatic like that π bye bestie, go count some intersections, mwah πβ¨
π¦ where this page comes from
- fedora 44: valkey-doc 9.0.3-2.fc44 Β· CC-BY-SA-4.0
- fedora 44: valkey-doc 9.0.6-1.fc44 Β· CC-BY-SA-4.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms