{
  "schema_version": 2,
  "id": "commands/zdiffstore",
  "title": "ZDIFFSTORE",
  "url": "https://redis.io/docs/latest/commands/zdiffstore/",
  "summary": "Stores the difference of multiple sorted sets in a key.",
  "since": "6.2.0",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-09-18T09:48:43+01:00",
  "page_type": "content",
  "content_hash": "63dd41647004e06c570522a945eb333e9563dc762f78714189eec811fa8e82d5",
  "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\nComputes the difference between the first and all successive input sorted sets\nand stores the result in `destination`. The total number of input keys is\nspecified by `numkeys`.\n\nKeys that do not exist are considered to be empty sets.\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 sorted set in.\n\n</details>\n\n<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 sorted-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> ZADD zset1 1 \"one\"\n(integer) 1\nredis> ZADD zset1 2 \"two\"\n(integer) 1\nredis> ZADD zset1 3 \"three\"\n(integer) 1\nredis> ZADD zset2 1 \"one\"\n(integer) 1\nredis> ZADD zset2 2 \"two\"\n(integer) 1\nredis> ZDIFFSTORE out 2 zset1 zset2\n(integer) 1\nredis> ZRANGE out 0 -1 WITHSCORES\n1) \"three\"\n2) \"3\""
    },
    {
      "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 members in the resulting sorted set at _destination_.\n\n**RESP3:**\n\n[Integer reply](../../develop/reference/protocol-spec#integers): the number of members in the resulting sorted set at _destination_."
    }
  ],
  "examples": []
}
