{
  "id": "sunioncard",
  "title": "SUNIONCARD",
  "url": "https://redis.io/docs/latest/commands/sunioncard/",
  "summary": "Returns the number of members of the union of multiple 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": "a424295231b4a724f23e36a3fc13e7f5c16ff5719eb6f4ab24ae07429d75a6fa",
  "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 union of the given sets. This is the count-only counterpart of [`SUNION`](https://redis.io/docs/latest/commands/sunion): it returns just the number of distinct elements in the union, 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 to union.\n\n</details>"
    },
    {
      "id": "optional-arguments",
      "title": "Optional arguments",
      "role": "parameters",
      "text": "<details open><summary><code>APPROX</code></summary>\n\nReturn an approximate cardinality instead of an exact count.\n\n</details>\n\n<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 union 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 union cardinality. `LIMIT` works in both exact and approximate modes."
    },
    {
      "id": "approximate-cardinality",
      "title": "Approximate cardinality",
      "role": "content",
      "text": "By default, `SUNIONCARD` returns the exact union cardinality. With the `APPROX` option, it instead uses [HyperLogLog](https://redis.io/docs/latest/develop/data-types/probabilistic/hyperloglogs) internally to estimate the cardinality with a standard error of about 0.81%, without materializing the full union. This is useful for very large unions, where computing an exact count is expensive in both time and memory."
    },
    {
      "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 union.\n\n**RESP3:**\n\n[Integer reply](../../develop/reference/protocol-spec#integers): the number of elements in the resulting union."
    },
    {
      "id": "see-also",
      "title": "See also",
      "role": "related",
      "text": "[`SUNION`](https://redis.io/docs/latest/commands/sunion/) | [`SUNIONSTORE`](https://redis.io/docs/latest/commands/sunionstore/)"
    },
    {
      "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> SUNION key1 key2\n1) \"a\"\n2) \"c\"\n3) \"d\"\n4) \"b\"\n5) \"e\"\n> SUNIONCARD 2 key1 key2\n(integer) 5\n> SUNIONCARD 2 key1 key2 LIMIT 3\n(integer) 3",
      "section_id": "examples"
    }
  ]
}
