Mzunionstore
Bun

method

RedisClient.zunionstore

destination: KeyLike,
numkeys: number,
...args: string | number[]
): Promise<number>;

Compute the union of multiple sorted sets and store in destination

This command is similar to ZUNION, but instead of returning the result, it stores it in the destination key. If the destination key already exists, it is overwritten.

Options:

  • WEIGHTS: Multiply the score of each member in the corresponding sorted set by the given weight before aggregation
  • AGGREGATE SUM|MIN|MAX: Specify how the scores are aggregated (default: SUM)
@param destination

The destination key to store the result

@param numkeys

The number of input keys (sorted sets)

@returns

Promise that resolves with the number of elements in the resulting sorted set

// Set up sorted sets
await redis.zadd("zset1", "1", "a", "2", "b", "3", "c");
await redis.zadd("zset2", "4", "b", "5", "c", "6", "d");

// Basic union store
const count1 = await redis.zunionstore("out", 2, "zset1", "zset2");
// Returns: 4 (stored "a", "b", "c", "d" in "out")

// With weights
const count2 = await redis.zunionstore("out2", 2, "zset1", "zset2", "WEIGHTS", "2", "3");
// Returns: 4

// With MAX aggregation
const count3 = await redis.zunionstore("out3", 2, "zset1", "zset2", "AGGREGATE", "MAX");
// Returns: 4 (stores maximum scores)

Referenced types

type KeyLike = string | ArrayBufferView | Blob