Back to Redis

ZUNION

content/commands/zunion.md

latest1.5 KB
Original Source

{{< note >}} This command's behavior varies in clustered Redis environments. See the [multi-key operations]({{< relref "/develop/using-commands/multi-key-operations" >}}) page for more information. {{< /note >}}

This command is similar to [ZUNIONSTORE]({{< relref "/commands/zunionstore" >}}), but instead of storing the resulting sorted set, it is returned to the client.

For a description of the WEIGHTS and AGGREGATE options, see [ZUNIONSTORE]({{< relref "/commands/zunionstore" >}}).

Examples

{{% redis-cli %}} ZADD zset1 1 "one" ZADD zset1 2 "two" ZADD zset2 1 "one" ZADD zset2 2 "two" ZADD zset2 3 "three" ZUNION 2 zset1 zset2 ZUNION 2 zset1 zset2 WITHSCORES {{% /redis-cli %}}

Redis Software and Redis Cloud compatibility

| Redis Software | Redis Cloud | <span style="min-width: 9em; display: table-cell">Notes</span> | |:----------------------|:-----------------|:------| | <span title="Supported">✅ Standard</span> <span title="Supported"><nobr>✅ Active-Active</nobr></span> | <span title="Supported">✅ Standard</span> <span title="Supported"><nobr>✅ Active-Active</nobr></span> | |

Return information

{{< multitabs id="zunion-return-info" tab1="RESP2" tab2="RESP3" >}}

Array reply: the result of the union with, optionally, their scores when WITHSCORES is used.

-tab-sep-

Array reply: the result of the union with, optionally, their scores when WITHSCORES is used.

{{< /multitabs >}}