Mzrangestore
Bun

method

RedisClient.zrangestore

destination: KeyLike,
source: KeyLike,
start: string | number,
stop: string | number,
...options: string[]
): Promise<number>;

Store a range of members from a sorted set into a destination key

This command is like ZRANGE but stores the result in a destination key instead of returning it. Supports all the same options as ZRANGE including BYSCORE, BYLEX, REV, and LIMIT.

@param destination

The destination key to store results

@param source

The source sorted set key

@param start

The starting index or score

@param stop

The ending index or score

@param options

Optional flags: ["BYSCORE"], ["BYLEX"], ["REV"], ["LIMIT", offset, count]

@returns

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

// Add members to source set
await redis.send("ZADD", ["source", "1", "one", "2", "two", "3", "three"]);

// Store range by rank
const count1 = await redis.zrangestore("dest1", "source", 0, 1);
console.log(count1); // 2

// Store range by score
const count2 = await redis.zrangestore("dest2", "source", "1", "2", "BYSCORE");
console.log(count2); // 2

// Store in reverse order with limit
const count3 = await redis.zrangestore("dest3", "source", "0", "-1", "REV", "LIMIT", "0", "2");
console.log(count3); // 2

Referenced types

type KeyLike = string | ArrayBufferView | Blob