SINTERCARD

Syntax
SINTERCARD numkeys key [key ...] [LIMIT limit]
Available since:
7.0.0
Time complexity:
O(N*M) worst case where N is the cardinality of the smallest set and M is the number of sets.
ACL categories:
@read, @set, @slow,

此命令类似于SINTER,但它不返回结果集,而是只返回结果的基数。 返回所有给定集合交集的结果集的基数。

不存在的键被视为空集。 如果其中一个键是空集,结果集也是空的(因为与空集的交集总是产生空集)。

默认情况下,该命令计算所有给定集合的交集的基数。 当提供可选的LIMIT参数(默认为0,表示无限制)时,如果在计算过程中交集的基数达到限制,算法将退出并将限制作为基数。 这种实现确保了在限制低于实际交集基数的查询中显著加速。

示例

SADD key1 "a" SADD key1 "b" SADD key1 "c" SADD key1 "d" SADD key2 "c" SADD key2 "d" SADD key2 "e" SINTER key1 key2 SINTERCARD 2 key1 key2 SINTERCARD 2 key1 key2 LIMIT 1

RESP2/RESP3 回复

Integer reply: the number of elements in the resulting intersection.
RATE THIS PAGE
Back to top ↑