ZINTERCARD(3valkey)
β¨ ZINTERCARD β¨
valkey manual page, bestie β and yes we're doing the whole thing, so grab a snack π
NAME π
zintercard β returns the number of members of the intersect of multiple sorted sets. that's it, that's the girl. she counts. she does not return. iconic behavior honestly π
SYNOPSIS πΈ
ZINTERCARD numkeys key [key...] [LIMIT limit]
DESCRIPTION π¦
okay so. this command is basically ZINTER's sibling, but she's the low-key one β instead of handing you the whole result set, she just gives you the cardinality of the result. just the number. no extra drama. π
keys that don't exist? consider them empty sets, bestie. and if even one of your keys is an empty set, the resulting set is empty too β because set intersection with an empty set always gives you an empty set. math said no. π
by default, the command calculates 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 means unlimited β something cute happens: if the intersection cardinality reaches limit partway through the computation, the algorithm just exits and yields limit as the cardinality. and that implementation? it ensures a significant speedup for queries where the limit is lower than the actual intersection cardinality. queen of not doing extra work, we love to see it π₯
REPLY π
valkey-protocol(7) Integer reply: the number of members in the resulting intersection.
COMPLEXITY π§
O(N*K) worst case, with N being the smallest input sorted set and K being the number of input sorted sets.
ACL CATEGORIES π</bad>
@read @slow @sortedset
HISTORY β
- Available since:
7.0.0
EXAMPLES π
okay watch this, fr fr:
127.0.0.1:6379> ZADD zset1 1 "one"
(integer) 1
127.0.0.1:6379> ZADD zset1 2 "two"
(integer) 1
127.0.0.1:6379> ZADD zset2 1 "one"
(integer) 1
127.0.0.1:6379> ZADD zset2 2 "two"
(integer) 1
127.0.0.1:6379> ZADD zset2 3 "three"
(integer) 1
127.0.0.1:6379> ZINTER 2 zset1 zset2
1) "one"
2) "two"
127.0.0.1:6379> ZINTERCARD 2 zset1 zset2
(integer) 2
127.0.0.1:6379> ZINTERCARD 2 zset1 zset2 LIMIT 1
(integer) 1
see how ZINTER spills the whole tea and ZINTERCARD is like "it's 2, bye"? and with LIMIT 1 she doesn't even finish counting β she already knows it's 1 and dips. main character energy, no cap π«Ά
SEE ALSO π
bzmpop(3valkey)bzpopmax(3valkey)bzpopmin(3valkey)zadd(3valkey)zcard(3valkey)zcount(3valkey)zdiff(3valkey)zdiffstore(3valkey)zincrby(3valkey)zinter(3valkey)zinterstore(3valkey)zlexcount(3valkey)zmpop(3valkey)zmscore(3valkey)zpopmax(3valkey)zpopmin(3valkey)zrandmember(3valkey)zrange(3valkey)zrangebylex(3valkey)zrangebyscore(3valkey)zrangestore(3valkey)zrank(3valkey)zrem(3valkey)zremrangebylex(3valkey)zremrangebyrank(3valkey)zremrangebyscore(3valkey)zrevrange(3valkey)zrevrangebylex(3valkey)zrevrangebyscore(3valkey)zrevrank(3valkey)zscan(3valkey)zscore(3valkey)zunion(3valkey)zunionstore(3valkey)
and that's the whole page, bestie!! π¦ this was Valkey manual version 9.0.0, dated 2025-10-21, and you were reading ZINTERCARD(3valkey). go count something. slay πβ¨π
π¦ 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