Mzrange
Bun

method

RedisClient.zrange

key: KeyLike,
start: string | number,
stop: string | number,
withscores: 'WITHSCORES'
): Promise<[string, number][]>;

Return a range of members in a sorted set with their scores

@param key

The sorted set key

@param start

The starting index

@param stop

The stopping index

@param withscores

Return members with their scores

@returns

Promise that resolves with an array of [member, score, member, score, ...]

const results = await redis.zrange("myzset", 0, -1, "WITHSCORES");
// Returns ["member1", "1.5", "member2", "2.5", ...]
key: KeyLike,
start: string | number,
stop: string | number,
byscore: 'BYSCORE'
): Promise<string[]>;

Return a range of members in a sorted set by score

@param key

The sorted set key

@param start

The minimum score (use "-inf" for negative infinity, "(" prefix for exclusive)

@param stop

The maximum score (use "+inf" for positive infinity, "(" prefix for exclusive)

@param byscore

Indicates score-based range

@returns

Promise that resolves with an array of members with scores in the range

// Get members with score between 1 and 3
const members = await redis.zrange("myzset", "1", "3", "BYSCORE");

// Get members with score > 1 and <= 3 (exclusive start)
const members2 = await redis.zrange("myzset", "(1", "3", "BYSCORE");
key: KeyLike,
start: string,
stop: string,
bylex: 'BYLEX'
): Promise<string[]>;

Return a range of members in a sorted set lexicographically

@param key

The sorted set key

@param start

The minimum lexicographical value (use "-" for start, "[" for inclusive, "(" for exclusive)

@param stop

The maximum lexicographical value (use "+" for end, "[" for inclusive, "(" for exclusive)

@param bylex

Indicates lexicographical range

@returns

Promise that resolves with an array of members in the lexicographical range

// Get members lexicographically from "a" to "c" (inclusive)
const members = await redis.zrange("myzset", "[a", "[c", "BYLEX");
key: KeyLike,
start: string | number,
stop: string | number,
...options: string[]
): Promise<string[]>;

Return a range of members in a sorted set with various options

@param key

The sorted set key

@param start

The starting value (index, score, or lex depending on options)

@param stop

The stopping value

@param options

Additional options (BYSCORE, BYLEX, REV, LIMIT offset count, WITHSCORES)

@returns

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

// Get members by score with limit
const members = await redis.zrange("myzset", "1", "10", "BYSCORE", "LIMIT", "0", "5");

// Get members in reverse order with scores
const reversed = await redis.zrange("myzset", "0", "-1", "REV", "WITHSCORES");
key: KeyLike,
start: string | number,
stop: string | number
): Promise<string[]>;

Return a range of members in a sorted set

Returns the specified range of elements in the sorted set stored at key. The elements are considered to be ordered from the lowest to the highest score by default.

@param key

The sorted set key

@param start

The starting index (0-based, can be negative to count from end)

@param stop

The stopping index (0-based, can be negative to count from end)

@returns

Promise that resolves with an array of members in the specified range

// Get all members
const members = await redis.zrange("myzset", 0, -1);

// Get first 3 members
const top3 = await redis.zrange("myzset", 0, 2);

Referenced types

type KeyLike = string | ArrayBufferView | Blob