Mzrangebyscore
Bun

method

RedisClient.zrangebyscore

key: KeyLike,
min: string | number,
max: string | number
): Promise<string[]>;

Return members in a sorted set with scores within a given range

Returns all the elements in the sorted set at key with a score between min and max (inclusive by default). The elements are considered to be ordered from low to high scores.

Score ranges support:

  • -inf and +inf for negative and positive infinity
  • ( prefix for exclusive bounds (e.g., (5 means greater than 5, not including 5)
@param key

The sorted set key

@param min

Minimum score (can be "-inf", a number, or prefixed with "(" for exclusive)

@param max

Maximum score (can be "+inf", a number, or prefixed with "(" for exclusive)

@returns

Promise that resolves with array of members

await redis.send("ZADD", ["myzset", "1", "one", "2", "two", "3", "three"]);
const members = await redis.zrangebyscore("myzset", 1, 2);
// Returns: ["one", "two"]
key: KeyLike,
min: string | number,
max: string | number,
withscores: 'WITHSCORES'
): Promise<[string, number][]>;

Return members in a sorted set with scores within a given range, with scores

@param key

The sorted set key

@param min

Minimum score

@param max

Maximum score

@param withscores

The "WITHSCORES" keyword to return scores along with members

@returns

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

await redis.send("ZADD", ["myzset", "1", "one", "2", "two", "3", "three"]);
const result = await redis.zrangebyscore("myzset", 1, 2, "WITHSCORES");
// Returns: ["one", "1", "two", "2"]
key: KeyLike,
min: string | number,
max: string | number,
limit: 'LIMIT',
offset: number,
count: number
): Promise<string[]>;

Return members in a sorted set with scores within a given range, with pagination

@param key

The sorted set key

@param min

Minimum score

@param max

Maximum score

@param limit

The "LIMIT" keyword

@param offset

The number of elements to skip

@param count

The maximum number of elements to return

@returns

Promise that resolves with array of members

await redis.send("ZADD", ["myzset", "1", "one", "2", "two", "3", "three", "4", "four"]);
const result = await redis.zrangebyscore("myzset", "-inf", "+inf", "LIMIT", 1, 2);
// Returns: ["two", "three"]
key: KeyLike,
min: string | number,
max: string | number,
withscores: 'WITHSCORES',
...options: string | number[]
): Promise<[string, number][]>;

Return members in a sorted set with scores within a given range, with the score values

@param key

The sorted set key

@param min

Minimum score

@param max

Maximum score

@param options

Additional options (WITHSCORES, LIMIT offset count)

@returns

Promise that resolves with array of members (and scores if WITHSCORES is used)

key: KeyLike,
min: string | number,
max: string | number,
withscores: 'WITHSCORES',
limit: 'LIMIT',
offset: number,
count: number,
...options: string | number[]
): Promise<[string, number][]>;

Return members in a sorted set with scores within a given range, with the score values

@param key

The sorted set key

@param min

Minimum score

@param max

Maximum score

@param options

Additional options (WITHSCORES, LIMIT offset count)

@returns

Promise that resolves with array of members (and scores if WITHSCORES is used)

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

Return members in a sorted set with scores within a given range, with various options

@param key

The sorted set key

@param min

Minimum score

@param max

Maximum score

@param options

Additional options (WITHSCORES, LIMIT offset count)

@returns

Promise that resolves with array of members (and scores if WITHSCORES is used)

Referenced types

type KeyLike = string | ArrayBufferView | Blob