{
  "schema_version": 2,
  "id": "commands/sdiffstore",
  "title": "SDIFFSTORE",
  "url": "https://redis.io/docs/latest/commands/sdiffstore/",
  "summary": "Stores the difference of multiple sets in a key.",
  "since": "1.0.0",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-09-18T09:47:41+01:00",
  "page_type": "content",
  "content_hash": "578fc1b806e3822257adb571a0d6d14283258fc30b734ca482136fce7eb0b19c",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "> [!NOTE]\n> 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\nThis command is equal to [`SDIFF`](https://redis.io/docs/latest/commands/sdiff), but instead of returning the resulting set, it\nis stored in `destination`.\n\nIf `destination` already exists, it is overwritten."
    },
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open><summary><code>destination</code></summary>\n\nThe key to store the resulting set in.\n\n</details>\n\n<details open><summary><code>key [key ...]</code></summary>\n\nOne or more set keys. The difference is the members of the first set that are not present in any of the subsequent sets.\n\n</details>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "redis> SADD key1 \"a\"\n(integer) 1\nredis> SADD key1 \"b\"\n(integer) 1\nredis> SADD key1 \"c\"\n(integer) 1\nredis> SADD key2 \"c\"\n(integer) 1\nredis> SADD key2 \"d\"\n(integer) 1\nredis> SADD key2 \"e\"\n(integer) 1\nredis> SDIFFSTORE key key1 key2\n(integer) 2\nredis> SMEMBERS key\n1) \"a\"\n2) \"b\""
    },
    {
      "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=\"Supported\">&#x2705; Standard</span><br /><span title=\"Supported\"><nobr>&#x2705; Active-Active</nobr></span> | <span title=\"Supported\">&#x2705; Standard</span><br /><span title=\"Supported\"><nobr>&#x2705; 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 set.\n\n**RESP3:**\n\n[Integer reply](../../develop/reference/protocol-spec#integers): the number of elements in the resulting set."
    },
    {
      "id": "see-also",
      "title": "See also",
      "role": "related",
      "text": "[`SDIFF`](https://redis.io/docs/latest/commands/sdiff) | [`SDIFFCARD`](https://redis.io/docs/latest/commands/sdiffcard)"
    }
  ],
  "examples": []
}
