Mzinter
Bun

method

RedisClient.zinter

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

Compute the intersection of multiple sorted sets

Returns the members of the set resulting from the intersection of all the given sorted sets. Keys that do not exist are considered to be empty sets.

By default, the resulting score of each member is the sum of its scores in the sorted sets where it exists.

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: Return the scores along with the members
@param numkeys

The number of input keys (sorted sets)

@returns

Promise that resolves with an array of members (or [member, score] pairs if WITHSCORES)

// 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 - returns members that exist in all sets
const result1 = await redis.zinter(2, "zset1", "zset2");
// Returns: ["b", "c"]

// With scores (sum by default)
const result2 = await redis.zinter(2, "zset1", "zset2", "WITHSCORES");
// Returns: ["b", "3", "c", "5"] (b: 2+1=3, c: 3+2=5)

// With weights
const result3 = await redis.zinter(2, "zset1", "zset2", "WEIGHTS", "2", "3", "WITHSCORES");
// Returns: ["b", "7", "c", "12"] (b: 2*2+1*3=7, c: 3*2+2*3=12)

// With MIN aggregation
const result4 = await redis.zinter(2, "zset1", "zset2", "AGGREGATE", "MIN", "WITHSCORES");
// Returns: ["b", "1", "c", "2"] (minimum scores)
numkeys: number,
...args: string | number[]
): Promise<string[]>;

Compute the intersection of multiple sorted sets

Returns the members of the set resulting from the intersection of all the given sorted sets. Keys that do not exist are considered to be empty sets.

By default, the resulting score of each member is the sum of its scores in the sorted sets where it exists.

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: Return the scores along with the members
@param numkeys

The number of input keys (sorted sets)

@returns

Promise that resolves with an array of members (or [member, score] pairs if WITHSCORES)

// 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 - returns members that exist in all sets
const result1 = await redis.zinter(2, "zset1", "zset2");
// Returns: ["b", "c"]

// With scores (sum by default)
const result2 = await redis.zinter(2, "zset1", "zset2", "WITHSCORES");
// Returns: ["b", "3", "c", "5"] (b: 2+1=3, c: 3+2=5)

// With weights
const result3 = await redis.zinter(2, "zset1", "zset2", "WEIGHTS", "2", "3", "WITHSCORES");
// Returns: ["b", "7", "c", "12"] (b: 2*2+1*3=7, c: 3*2+2*3=12)

// With MIN aggregation
const result4 = await redis.zinter(2, "zset1", "zset2", "AGGREGATE", "MIN", "WITHSCORES");
// Returns: ["b", "1", "c", "2"] (minimum scores)