Mzrevrangebylex
Bun

method

RedisClient.zrevrangebylex

key: KeyLike,
max: string,
min: string,
...options: string[]
): Promise<string[]>;

Return members in a sorted set within a lexicographical range, ordered from high to low

All members in a sorted set must have the same score for this command to work correctly. The max and min arguments have the same meaning as in ZRANGEBYLEX, but in reverse order.

Use "[" for inclusive bounds and "(" for exclusive bounds. Use "-" for negative infinity and "+" for positive infinity.

@param key

The sorted set key

@param max

The maximum lexicographical value (inclusive with "[", exclusive with "(")

@param min

The minimum lexicographical value (inclusive with "[", exclusive with "(")

@param options

Optional LIMIT clause: ["LIMIT", offset, count]

@returns

Promise that resolves with an array of members in reverse lexicographical order

// Add members with same score
await redis.send("ZADD", ["myzset", "0", "a", "0", "b", "0", "c", "0", "d"]);

// Get range from highest to lowest
const members = await redis.zrevrangebylex("myzset", "[d", "[b");
console.log(members); // ["d", "c", "b"]

// With LIMIT
const limited = await redis.zrevrangebylex("myzset", "+", "-", "LIMIT", "0", "2");
console.log(limited); // ["d", "c"] (first 2 members)

Referenced types

type KeyLike = string | ArrayBufferView | Blob