> ## Documentation Index
> Fetch the complete documentation index at: https://upstash.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# ZUNIONSTORE

> Writes the union between sets to a new key.

## Arguments

<ParamField body="destination" type="string" required>
  The key to write the union to.
</ParamField>

<ParamField body="keys" type="integer" required>
  How many keys to compare.
</ParamField>

<ParamField body="keys" type="string | string[]" required>
  The keys to compare.
</ParamField>

<ParamField body="options">
  <ParamField body="aggregate" type="sum | min | max">
    The aggregation method.
  </ParamField>

  <ParamField body="weight" type="number">
    The weight to apply to each key.
  </ParamField>

  <ParamField body="weights" type="number[]">
    The weights to apply to each key.
  </ParamField>
</ParamField>

## Response

<ResponseField required>
  The number of elements in the resulting set.
</ResponseField>

<RequestExample>
  ```ts Simple theme={"system"}
  await redis.zadd(
      "key1", 
      { score: 1, member: "member1" },
  )
  await redis.zadd(
      "key2",
      { score: 1, member: "member1" },
      { score: 2, member: "member2" },
  )

  const res = await redis.zunionstore("destination", 2, ["key1", "key2"]);
  console.log(res) // 2
  ```

  ```ts With Weights theme={"system"}
  await redis.zadd(
      "key1", 
      { score: 1, member: "member1" },
  )
  await redis.zadd(
      "key2",
      { score: 1, member: "member1" },
      { score: 2, member: "member2" },
  )
  const res = await redis.zunionstore(
      "destination",
      2,
      ["key1", "key2"],
      { weights: [2, 3] },
  );
  console.log(res) // 2
  ```

  ```ts Aggregate theme={"system"}
  await redis.zadd(
      "key1", 
      { score: 1, member: "member1" },
  )
  await redis.zadd(
      "key2",
      { score: 1, member: "member1" },
      { score: 2, member: "member2" },
  )
  const res = await redis.zunionstore(
      "destination",
      2,
      ["key1", "key2"],
      { aggregate: "sum" },
  );
  console.log(res) // 2
  ```
</RequestExample>
