Mzinterstore
Bun

method

RedisClient.zinterstore

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

Compute the intersection of multiple sorted sets and store in destination

This command is similar to ZINTER, 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", "1", "b", "2", "c", "3", "d");

// Basic intersection store
const count1 = await redis.zinterstore("out", 2, "zset1", "zset2");
// Returns: 2 (stored "b" and "c" in "out")

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

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

Referenced types

type KeyLike = string | ArrayBufferView | Blob