SINTERCARD(3valkey)

πŸ“¦
version 9.0.6 Β· 2 versions
, in fedora 44

πŸ’– 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