{
  "id": "sdiffcard",
  "title": "SDIFFCARD",
  "url": "https://redis.io/docs/latest/commands/sdiffcard/",
  "summary": "Returns the number of members of the difference between the first set and all successive sets.",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-07-30T08:54:30-07:00",
  "page_type": "content",
  "content_hash": "fcfb37d93dc6a51b8afd9c45ad238d7926a4adbe2e4a09132cde091c2b96797e",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "This command's behavior varies in clustered Redis environments. See the [multi-key operations](https://redis.io/docs/latest/develop/using-commands/multi-key-operations) page for more information.\n\n\n\nReturns the cardinality of the difference between the first set and all the successive sets. This is the count-only counterpart of [`SDIFF`](https://redis.io/docs/latest/commands/sdiff): it returns just the number of elements in the difference, not the members themselves."
    },
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open><summary><code>numkeys</code></summary>\n\nThe number of keys that follow.\n\n</details>\n\n<details open><summary><code>key [key ...]</code></summary>\n\nOne or more set keys. The result counts the members of the first set that are not present in any of the subsequent sets.\n\n</details>"
    },
    {
      "id": "optional-arguments",
      "title": "Optional arguments",
      "role": "parameters",
      "text": "<details open><summary><code>LIMIT limit</code></summary>\n\nStop counting once the cardinality reaches `limit`. `0` (the default) means no limit.\n\n</details>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "[code example]"
    },
    {
      "id": "details",
      "title": "Details",
      "role": "content",
      "text": "Keys that do not exist are considered to be empty sets.\n\nWhen provided with the optional `LIMIT` argument (which defaults to `0`, meaning unlimited), if the difference cardinality reaches `limit` partway through the computation, the command stops and returns `limit` as the cardinality. This ensures a significant speedup for queries where the limit is lower than the actual difference cardinality."
    },
    {
      "id": "redis-software-and-redis-cloud-compatibility",
      "title": "Redis Software and Redis Cloud compatibility",
      "role": "content",
      "text": "| Redis<br />Software | Redis<br />Cloud | <span style=\"min-width: 9em; display: table-cell\">Notes</span> |\n|:----------------------|:-----------------|:------|\n| <span title=\"Not supported\">&#x274c; Standard</span><br /><span title=\"Not supported\"><nobr>&#x274c; Active-Active</nobr></span> | <span title=\"Not supported\">&#x274c; Standard</span><br /><span title=\"Not supported\"><nobr>&#x274c; Active-Active</nobr></span> |  |"
    },
    {
      "id": "return-information",
      "title": "Return information",
      "role": "returns",
      "text": "**RESP2:**\n\n[Integer reply](../../develop/reference/protocol-spec#integers): the number of elements in the resulting difference.\n\n**RESP3:**\n\n[Integer reply](../../develop/reference/protocol-spec#integers): the number of elements in the resulting difference."
    },
    {
      "id": "see-also",
      "title": "See also",
      "role": "related",
      "text": "[`SDIFF`](https://redis.io/docs/latest/commands/sdiff/) | [`SDIFFSTORE`](https://redis.io/docs/latest/commands/sdiffstore/)"
    },
    {
      "id": "related-topics",
      "title": "Related topics",
      "role": "related",
      "text": "- [Redis sets](https://redis.io/docs/latest/develop/data-types/sets)\n- [Multi-key operations](https://redis.io/docs/latest/develop/using-commands/multi-key-operations)"
    }
  ],
  "examples": [
    {
      "id": "examples-ex0",
      "language": "plaintext",
      "code": "> SADD key1 \"a\"\n(integer) 1\n> SADD key1 \"b\"\n(integer) 1\n> SADD key1 \"c\"\n(integer) 1\n> SADD key2 \"c\"\n(integer) 1\n> SADD key2 \"d\"\n(integer) 1\n> SADD key2 \"e\"\n(integer) 1\n> SDIFF key1 key2\n1) \"b\"\n2) \"a\"\n> SDIFFCARD 2 key1 key2\n(integer) 2\n> SDIFFCARD 2 key1 key2 LIMIT 1\n(integer) 1",
      "section_id": "examples"
    }
  ]
}
