Skip to main content
Use SDIFFCARD to count the members of the first set that are not present in any of the other sets. It returns only the count; use SDIFF to retrieve the members. Keys that do not exist count as empty sets, so a missing first key returns 0. The command does not modify the source sets or store the difference. LIMIT stops counting once that many members have been found and returns the limit. For example, LIMIT 1 checks whether the difference contains any members. Omitting LIMIT or using LIMIT 0 returns the full count.

Syntax

Arguments

Important points

  • numkeys must equal the number of key arguments that immediately follow it.
  • Key order matters: the command subtracts the other sets from the first set.
  • With one key, the command returns that set’s cardinality, capped by a positive LIMIT.

Response

The number of members in the difference, capped by LIMIT when it is positive.

Examples

TCP examples use the TLS REDIS_URL from the Upstash console. Client examples query set1 and set2 from the Redis CLI example.
The difference contains a and b, so its cardinality is 2.
This command is not supported yet in @upstash/redis.
This command is not supported yet in upstash_redis.

Related topics

Changelog