import type { CommandOptions } from "./command"; import { Command } from "./command"; export type ZRangeCommandOptions = { withScores?: boolean; rev?: boolean; } & ( | { byScore: true; byLex?: never } | { byScore?: never; byLex: true } | { byScore?: never; byLex?: never } ) & ({ offset: number; count: number } | { offset?: never; count?: never }); /** * @see https://redis.io/commands/zrange * @see node_modules/@upstash/redis/docs/commands/zset/zrange.mdx * Responses are JSON-parsed automatically: a stored "123" comes back as the number 123, "true" as * true, and '{"a":1}' as an object. Pass automaticDeserialization: false to the Redis constructor * to receive raw strings. */ export class ZRangeCommand extends Command { constructor( cmd: [key: string, min: number, max: number, opts?: ZRangeCommandOptions], cmdOpts?: CommandOptions ); constructor( cmd: [ key: string, min: `(${string}` | `[${string}` | "-" | "+", max: `(${string}` | `[${string}` | "-" | "+", opts: { byLex: true } & ZRangeCommandOptions, ], cmdOpts?: CommandOptions ); constructor( cmd: [ key: string, min: number | `(${number}` | "-inf" | "+inf", max: number | `(${number}` | "-inf" | "+inf", opts: { byScore: true } & ZRangeCommandOptions, ], cmdOpts?: CommandOptions ); constructor( [key, min, max, opts]: [ key: string, min: number | string, max: number | string, opts?: ZRangeCommandOptions, ], cmdOpts?: CommandOptions ) { const command: unknown[] = ["zrange", key, min, max]; // Either byScore or byLex is allowed if (opts?.byScore) { command.push("byscore"); } if (opts?.byLex) { command.push("bylex"); } if (opts?.rev) { command.push("rev"); } if (opts?.count !== undefined && opts.offset !== undefined) { command.push("limit", opts.offset, opts.count); } if (opts?.withScores) { command.push("withscores"); } super(command, cmdOpts); } }