method

RedisClient.zunion

numkeys: number,
...args: [...args: string | number[], withscores: 'WITHSCORES']
): Promise<[string, number][]>;

Compute the union of multiple sorted sets

For every element that appears in at least one of the input sorted sets, the output contains that element.

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)
  • WITHSCORES: Include scores in the result
@param numkeys

The number of input keys (sorted sets)

@returns

Promise that resolves with an array of members (or members with scores if WITHSCORES is used)

// 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
const members1 = await redis.zunion(2, "zset1", "zset2");
// Returns: ["a", "b", "c", "d"]

// With weights
const members2 = await redis.zunion(2, "zset1", "zset2", "WEIGHTS", "2", "3");
// Returns: ["a", "b", "c", "d"] with calculated scores

// With MIN aggregation
const members3 = await redis.zunion(2, "zset1", "zset2", "AGGREGATE", "MIN");
// Returns: ["a", "b", "c", "d"] with minimum scores

// With scores
const withScores = await redis.zunion(2, "zset1", "zset2", "WITHSCORES");
// Returns: ["a", "1", "b", "2", "c", "3", "d", "6"] (alternating member and score)
numkeys: number,
...args: string | number[]
): Promise<string[]>;

Compute the union of multiple sorted sets

For every element that appears in at least one of the input sorted sets, the output contains that element.

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)
  • WITHSCORES: Include scores in the result
@param numkeys

The number of input keys (sorted sets)

@returns

Promise that resolves with an array of members (or members with scores if WITHSCORES is used)

// 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
const members1 = await redis.zunion(2, "zset1", "zset2");
// Returns: ["a", "b", "c", "d"]

// With weights
const members2 = await redis.zunion(2, "zset1", "zset2", "WEIGHTS", "2", "3");
// Returns: ["a", "b", "c", "d"] with calculated scores

// With MIN aggregation
const members3 = await redis.zunion(2, "zset1", "zset2", "AGGREGATE", "MIN");
// Returns: ["a", "b", "c", "d"] with minimum scores

// With scores
const withScores = await redis.zunion(2, "zset1", "zset2", "WITHSCORES");
// Returns: ["a", "1", "b", "2", "c", "3", "d", "6"] (alternating member and score)