{
  "schema_version": 2,
  "id": "commands/zunion",
  "title": "ZUNION",
  "url": "https://redis.io/docs/latest/commands/zunion/",
  "summary": "Returns the union of multiple sorted sets.",
  "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": "1d1a2e5825ddf4ed38fe60d28b81cd10d94cb764e1789fd9593b8b54f1a9c4e0",
  "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 similar to [`ZUNIONSTORE`](https://redis.io/docs/latest/commands/zunionstore), but instead of storing the resulting\nsorted set, it is returned to the client.\n\nFor a description of the `WEIGHTS` and `AGGREGATE` options, see [`ZUNIONSTORE`](https://redis.io/docs/latest/commands/zunionstore)."
    },
    {
      "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 sorted-set keys to union.\n\n</details>"
    },
    {
      "id": "optional-arguments",
      "title": "Optional arguments",
      "role": "parameters",
      "text": "<details open><summary><code>WEIGHTS weight [weight ...]</code></summary>\n\nA multiplication factor for each input set; each set's scores are multiplied by its weight before aggregation. Defaults to 1 for every set.\n\n</details>\n\n<details open><summary><code>AGGREGATE SUM | MIN | MAX | COUNT</code></summary>\n\nHow to combine the scores of members that exist in multiple sets: `SUM` (the default), `MIN`, `MAX`, or `COUNT`.\n\n</details>\n\n<details open><summary><code>WITHSCORES</code></summary>\n\nAlso return the score of each member.\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 zset2 1 \"one\"\n(integer) 1\nredis> ZADD zset2 2 \"two\"\n(integer) 1\nredis> ZADD zset2 3 \"three\"\n(integer) 1\nredis> ZUNION 2 zset1 zset2\n1) \"one\"\n2) \"three\"\n3) \"two\"\nredis> ZUNION 2 zset1 zset2 WITHSCORES\n1) \"one\"\n2) \"2\"\n3) \"three\"\n4) \"3\"\n5) \"two\"\n6) \"4\""
    },
    {
      "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[Array reply](../../develop/reference/protocol-spec#arrays): the result of the union with, optionally, their scores when _WITHSCORES_ is used.\n\n**RESP3:**\n\n[Array reply](../../develop/reference/protocol-spec#arrays): the result of the union with, optionally, their scores when _WITHSCORES_ is used."
    }
  ],
  "examples": []
}
