Return a range of members in a sorted set with their scores
method
RedisClient.zrange
The sorted set key
The starting index
The stopping index
Return members with their scores
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", ...]
Return a range of members in a sorted set by score
The sorted set key
The minimum score (use "-inf" for negative infinity, "(" prefix for exclusive)
The maximum score (use "+inf" for positive infinity, "(" prefix for exclusive)
Indicates score-based range
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");
Return a range of members in a sorted set lexicographically
The sorted set key
The minimum lexicographical value (use "-" for start, "[" for inclusive, "(" for exclusive)
The maximum lexicographical value (use "+" for end, "[" for inclusive, "(" for exclusive)
Indicates lexicographical range
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");
Return a range of members in a sorted set with various options
The sorted set key
The starting value (index, score, or lex depending on options)
The stopping value
Additional options (BYSCORE, BYLEX, REV, LIMIT offset count, WITHSCORES)
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");
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.
The sorted set key
The starting index (0-based, can be negative to count from end)
The stopping index (0-based, can be negative to count from end)
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);