// Type definitions for ioredis 4.17 // Project: https://github.com/luin/ioredis // Definitions by: York Yao // Christopher Eck // Yoga Aliarham // Ebrahim // Whemoon Jang // Francis Gulotta // Dmitry Motovilov // Oleg Repin // Ting-Wai To // Alex Petty // Simon Schick // Tianlin // Demian Rodriguez // Andrew Lavers // Claudiu Ceia // Asyrique // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 /* =================== USAGE =================== import * as Redis from "ioredis"; const redis = new Redis(); =============================================== */ /// import { ConnectionOptions } from 'tls'; import { Readable } from 'stream'; import { EventEmitter } from 'events'; interface RedisStatic { new (port?: number, host?: string, options?: IORedis.RedisOptions): IORedis.Redis; new (host?: string, options?: IORedis.RedisOptions): IORedis.Redis; new (options?: IORedis.RedisOptions): IORedis.Redis; (port?: number, host?: string, options?: IORedis.RedisOptions): IORedis.Redis; (host?: string, options?: IORedis.RedisOptions): IORedis.Redis; (options?: IORedis.RedisOptions): IORedis.Redis; Cluster: IORedis.ClusterStatic; Command: typeof Command; } declare var IORedis: RedisStatic; export = IORedis; declare class Commander { getBuiltinCommands(): string[]; createBuiltinCommand(commandName: string): {}; defineCommand( name: string, definition: { numberOfKeys?: number; lua?: string; }, ): void; sendCommand(): void; } interface CommandOptions { replyEncoding?: string | null; errorStack?: string; keyPrefix?: string; } declare class Command { isCustomCommand: boolean; args: IORedis.ValueType[]; getSlot(): number | null; getKeys(): Array; constructor( name: string, args: IORedis.ValueType[], opts?: CommandOptions, callback?: (err: null, result: any) => void, ); static setArgumentTransformer(name: string, fn: (args: IORedis.ValueType[]) => IORedis.ValueType[]): void; static setReplyTransformer(name: string, fn: (result: any) => any): void; } // For backwards compatibility type _Command = typeof Command; declare namespace IORedis { type BooleanResponse = 1 | 0; type Callback = (err: Error | null, res: T) => void; type KeyType = string | Buffer; type ValueType = string | Buffer | number | any[]; interface OverloadedCommand { (arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, arg6: T, cb: Callback): void; (arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, cb: Callback): void; (arg1: T, arg2: T, arg3: T, arg4: T, cb: Callback): void; (arg1: T, arg2: T, arg3: T, cb: Callback): void; (arg1: T, arg2: T, cb: Callback): void; (arg1: T | T[], cb: Callback): void; (cb: Callback): void; (...args: T[]): Promise; (arg1: T[]): Promise; } interface OverloadedListCommand { (arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, arg6: T, cb: Callback): void; (arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, cb: Callback): void; (arg1: T, arg2: T, arg3: T, arg4: T, cb: Callback): void; (arg1: T, arg2: T, arg3: T, cb: Callback): void; (arg1: T, arg2: T, cb: Callback): void; (arg1: T | T[], cb: Callback): void; (...args: T[]): Promise; (arg1: T[]): Promise; } interface OverloadedBlockingListCommand { (arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, arg6: T, timeout: number, cb: Callback): void; (arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, timeout: number, cb: Callback): void; (arg1: T, arg2: T, arg3: T, arg4: T, timeout: number, cb: Callback): void; (arg1: T, arg2: T, arg3: T, timeout: number, cb: Callback): void; (arg1: T, arg2: T, timeout: number, cb: Callback): void; (arg1: T, timeout: number, cb: Callback): void; (arg1: Array, cb: Callback): void; (...args: Array): Promise; (arg1: Array): Promise; } interface OverloadedSubCommand { (arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, arg6: T, cb: Callback): void; (arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, cb: Callback): void; (arg1: T, arg2: T, arg3: T, arg4: T, cb: Callback): void; (arg1: T, arg2: T, arg3: T, cb: Callback): void; (arg1: T, arg2: T | T[], cb: Callback): void; (arg1: T | T[], cb: Callback): void; (...args: T[]): Promise; (arg1: T[]): Promise; } interface OverloadedKeyCommand { (key: KeyType, arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, arg6: T, cb: Callback): void; (key: KeyType, arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, cb: Callback): void; (key: KeyType, arg1: T, arg2: T, arg3: T, arg4: T, cb: Callback): void; (key: KeyType, arg1: T, arg2: T, arg3: T, cb: Callback): void; (key: KeyType, arg1: T, arg2: T, cb: Callback): void; (key: KeyType, arg1: T | T[], cb: Callback): void; (key: KeyType, ...args: T[]): Promise; (key: KeyType, arg1: T[]): Promise; } interface OverloadedHashCommand { (arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, arg6: T, cb: Callback): void; (arg1: T, arg2: T, arg3: T, arg4: T, cb: Callback): void; (arg1: T, arg2: T, cb: Callback): void; (data: T[] | { [key: string]: T } | Map, cb: Callback): void; (data: T[] | { [key: string]: T } | Map): Promise; (...args: T[]): Promise; } interface OverloadedKeyedHashCommand { (key: KeyType, arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, arg6: T, cb: Callback): void; (key: KeyType, arg1: T, arg2: T, arg3: T, arg4: T, cb: Callback): void; (key: KeyType, arg1: T, arg2: T, cb: Callback): void; (key: KeyType, data: T[] | { [key: string]: T } | Map, cb: Callback): void; (key: KeyType, data: T[] | { [key: string]: T } | Map): Promise; (key: KeyType, ...args: T[]): Promise; } interface OverloadedEvalCommand { (script: string, numKeys: number, arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, arg6: T, cb: Callback): void; (script: string, numKeys: number, arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, cb: Callback): void; (script: string, numKeys: number, arg1: T, arg2: T, arg3: T, arg4: T, cb: Callback): void; (script: string, numKeys: number, arg1: T, arg2: T, arg3: T, cb: Callback): void; (script: string, numKeys: number, arg1: T, arg2: T, cb: Callback): void; (script: string, numKeys: number, arg1: T | T[], cb: Callback): void; (script: string, numKeys: number, ...args: T[]): Promise; (script: string, numKeys: number, arg1: T[]): Promise; // This overload exists specifically to retain compatibility to `redlock` // All arguments are by default flattened, declaring all possible permuatations // would be unreasonable (and probably impossible) (args: ValueType[], callback?: Callback): any; } interface OverloadedScanCommand { (key: string, cursor: number, arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, arg6: T, cb: Callback): void; (key: string, cursor: number, arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, cb: Callback): void; (key: string, cursor: number, arg1: T, arg2: T, arg3: T, arg4: T, cb: Callback): void; (key: string, cursor: number, arg1: T, arg2: T, arg3: T, cb: Callback): void; (key: string, cursor: number, arg1: T, arg2: T, cb: Callback): void; (key: string, cursor: number, arg1: T | T[], cb: Callback): void; (key: string, cursor: number, cb: Callback): void; (key: string, cursor: number, ...args: T[]): Promise; (key: string, cursor: number, arg1: T[]): Promise; } type Command = _Command; interface Commands { bitcount(key: KeyType, callback: Callback): void; bitcount(key: KeyType, start: number, end: number, callback: (err: Error, res: number) => void): void; bitcount(key: KeyType): Promise; bitcount(key: KeyType, start: number, end: number): Promise; get(key: KeyType, callback: Callback): void; get(key: KeyType): Promise; getBuffer(key: KeyType, callback: Callback): void; getBuffer(key: KeyType): Promise; set( key: KeyType, value: ValueType, expiryMode?: string | any[], time?: number | string, setMode?: number | string, ): Promise; set(key: KeyType, value: ValueType, callback: Callback): void; set(key: KeyType, value: ValueType, setMode: string | any[], callback: Callback): void; set(key: KeyType, value: ValueType, expiryMode: string, time: number | string, callback: Callback): void; set( key: KeyType, value: ValueType, expiryMode: string, time: number | string, setMode: number | string, callback: Callback, ): void; setBuffer( key: KeyType, value: ValueType, expiryMode?: string | any[], time?: number | string, setMode?: number | string, ): Promise; setBuffer(key: KeyType, value: ValueType, callback: Callback): void; setBuffer(key: KeyType, value: ValueType, setMode: string, callback: Callback): void; setBuffer(key: KeyType, value: ValueType, expiryMode: string, time: number, callback: Callback): void; setBuffer( key: KeyType, value: ValueType, expiryMode: string, time: number | string, setMode: number | string, callback: Callback, ): void; setnx(key: KeyType, value: ValueType, callback: Callback): void; setnx(key: KeyType, value: ValueType): Promise; setex(key: KeyType, seconds: number, value: ValueType, callback: Callback): void; setex(key: KeyType, seconds: number, value: ValueType): Promise; psetex(key: KeyType, milliseconds: number, value: ValueType, callback: Callback): void; psetex(key: KeyType, milliseconds: number, value: ValueType): Promise; append(key: KeyType, value: ValueType, callback: Callback): void; append(key: KeyType, value: ValueType): Promise; strlen(key: KeyType, callback: Callback): void; strlen(key: KeyType): Promise; del: OverloadedListCommand; unlink: OverloadedListCommand; exists(...keys: KeyType[]): Promise; exists(key: KeyType, callback: Callback): void; setbit(key: KeyType, offset: number, value: ValueType, callback: Callback): void; setbit(key: KeyType, offset: number, value: ValueType): Promise; getbit(key: KeyType, offset: number, callback: Callback): void; getbit(key: KeyType, offset: number): Promise; setrange(key: KeyType, offset: number, value: ValueType, callback: Callback): void; setrange(key: KeyType, offset: number, value: ValueType): Promise; getrange(key: KeyType, start: number, end: number, callback: Callback): void; getrange(key: KeyType, start: number, end: number): Promise; substr(key: KeyType, start: number, end: number, callback: Callback): void; substr(key: KeyType, start: number, end: number): Promise; incr(key: KeyType, callback: Callback): void; incr(key: KeyType): Promise; decr(key: KeyType, callback: Callback): void; decr(key: KeyType): Promise; mget: OverloadedListCommand>; rpush: OverloadedKeyCommand; rpushBuffer: OverloadedKeyCommand; lpush: OverloadedKeyCommand; lpushBuffer: OverloadedKeyCommand; rpushx: OverloadedKeyCommand; lpushx: OverloadedKeyCommand; linsert( key: KeyType, direction: 'BEFORE' | 'AFTER', pivot: string, value: ValueType, callback: Callback, ): void; linsert(key: KeyType, direction: 'BEFORE' | 'AFTER', pivot: string, value: ValueType): Promise; rpop(key: KeyType, callback: Callback): void; rpop(key: KeyType): Promise; lpop(key: KeyType, callback: Callback): void; lpop(key: KeyType): Promise; lpopBuffer(key: KeyType, callback: Callback): void; lpopBuffer(key: KeyType): Promise; brpop: OverloadedBlockingListCommand; blpop: OverloadedBlockingListCommand; brpoplpush(source: string, destination: string, timeout: number, callback: Callback): void; brpoplpush(source: string, destination: string, timeout: number): Promise; llen(key: KeyType, callback: Callback): void; llen(key: KeyType): Promise; lindex(key: KeyType, index: number, callback: Callback): void; lindex(key: KeyType, index: number): Promise; lset(key: KeyType, index: number, value: ValueType, callback: Callback): void; lset(key: KeyType, index: number, value: ValueType): Promise; lrange(key: KeyType, start: number, stop: number, callback: Callback): void; lrange(key: KeyType, start: number, stop: number): Promise; lrangeBuffer(key: KeyType, start: number, stop: number, callback: Callback): void; lrangeBuffer(key: KeyType, start: number, stop: number): Promise; ltrim(key: KeyType, start: number, stop: number, callback: Callback): void; ltrim(key: KeyType, start: number, stop: number): Promise; lrem(key: KeyType, count: number, value: ValueType, callback: Callback): void; lrem(key: KeyType, count: number, value: ValueType): Promise; rpoplpush(source: string, destination: string, callback: Callback): void; rpoplpush(source: string, destination: string): Promise; rpoplpushBuffer(source: string, destination: string, callback: Callback): void; rpoplpushBuffer(source: string, destination: string): Promise; sadd: OverloadedKeyCommand; srem: OverloadedKeyCommand; smove(source: string, destination: string, member: string, callback: Callback): void; smove(source: string, destination: string, member: string): Promise; sismember(key: KeyType, member: string, callback: Callback): void; sismember(key: KeyType, member: string): Promise; scard(key: KeyType, callback: Callback): void; scard(key: KeyType): Promise; spop(key: KeyType, callback: Callback): void; spop(key: KeyType): Promise; spop(key: KeyType, count: number, callback: Callback): void; spop(key: KeyType, count: number): Promise; srandmember(key: KeyType, callback: Callback): void; srandmember(key: KeyType): Promise; srandmember(key: KeyType, count: number, callback: Callback): void; srandmember(key: KeyType, count: number): Promise; sinter: OverloadedListCommand; sinterstore: OverloadedKeyCommand; sunion: OverloadedListCommand; sunionstore: OverloadedKeyCommand; sdiff: OverloadedListCommand; sdiffstore: OverloadedKeyCommand; smembers(key: KeyType, callback: Callback): void; smembers(key: KeyType): Promise; zadd: OverloadedKeyCommand; zaddBuffer(key: KeyType, score1: number, member1: Buffer, callback: Callback): void; zaddBuffer(key: KeyType, score1: number, member1: Buffer): Promise; zincrby(key: KeyType, increment: number, member: string, callback: Callback): void; zincrby(key: KeyType, increment: number, member: string): Promise; zpopmin(key: KeyType, callback: Callback): void; zpopmin(key: KeyType, count: number, callback: Callback): void; zpopmin(key: KeyType, count?: number): Promise; zpopmax(key: KeyType, callback: Callback): void; zpopmax(key: KeyType, count: number, callback: Callback): void; zpopmax(key: KeyType, count?: number): Promise; zrem: OverloadedKeyCommand; zremrangebyscore(key: KeyType, min: number | string, max: number | string, callback: Callback): void; zremrangebyscore(key: KeyType, min: number | string, max: number | string): Promise; zremrangebyrank(key: KeyType, start: number, stop: number, callback: Callback): void; zremrangebyrank(key: KeyType, start: number, stop: number): Promise; zremrangebylex( key: KeyType, min: string, max: string, ): Promise; zremrangebylex( key: KeyType, min: string, max: string, callback: Callback ): void; zunionstore: OverloadedKeyCommand; zinterstore: OverloadedKeyCommand; zrange(key: KeyType, start: number, stop: number, callback: Callback): void; zrange(key: KeyType, start: number, stop: number, withScores: 'WITHSCORES', callback: Callback): void; zrange(key: KeyType, start: number, stop: number, withScores?: 'WITHSCORES'): Promise; zrevrange(key: KeyType, start: number, stop: number, callback: Callback): void; zrevrange( key: KeyType, start: number, stop: number, withScores: 'WITHSCORES', callback: Callback, ): void; zrevrange(key: KeyType, start: number, stop: number, withScores?: 'WITHSCORES'): Promise; zrangebyscore( key: KeyType, min: number | string, max: number | string, withScores?: 'WITHSCORES', ): Promise; zrangebyscore( key: KeyType, min: number | string, max: number | string, withScores: 'WITHSCORES', limit: 'LIMIT', offset: number, count: number, ): Promise; zrangebyscore( key: KeyType, min: number | string, max: number | string, limit: 'LIMIT', offset: number, count: number, ): Promise; zrangebyscore(key: KeyType, min: number | string, max: number | string, callback: Callback): void; zrangebyscore( key: KeyType, min: number | string, max: number | string, withScores: 'WITHSCORES', callback: Callback, ): void; zrangebyscore( key: KeyType, min: number | string, max: number | string, withScores: 'WITHSCORES', limit: 'LIMIT', offset: number, count: number, callback: Callback, ): void; zrangebyscore( key: KeyType, min: number | string, max: number | string, limit: 'LIMIT', offset: number, count: number, callback: Callback, ): void; zrevrangebyscore( key: KeyType, max: number | string, min: number | string, withScores?: 'WITHSCORES', ): Promise; zrevrangebyscore( key: KeyType, max: number | string, min: number | string, withScores: 'WITHSCORES', limit: 'LIMIT', offset: number, count: number, ): Promise; zrevrangebyscore( key: KeyType, max: number | string, min: number | string, limit: 'LIMIT', offset: number, count: number, ): Promise; zrevrangebyscore(key: KeyType, max: number | string, min: number | string, callback: Callback): void; zrevrangebyscore( key: KeyType, max: number | string, min: number | string, withScores: 'WITHSCORES', callback: Callback, ): void; zrevrangebyscore( key: KeyType, max: number | string, min: number | string, withScores: 'WITHSCORES', limit: 'LIMIT', offset: number, count: number, callback: Callback, ): void; zrevrangebyscore( key: KeyType, max: number | string, min: number | string, limit: 'LIMIT', offset: number, count: number, callback: Callback, ): void; zrangebylex( key: KeyType, min: string, max: string, ): Promise; zrangebylex( key: KeyType, min: string, max: string, limit: 'LIMIT', offset: number, count: number, ): Promise; zrangebylex( key: KeyType, min: string, max: string, callback: Callback, ): void; zrangebylex( key: KeyType, min: string, max: string, limit: 'LIMIT', offset: number, count: number, callback: Callback, ): void; zrevrangebylex( key: KeyType, min: string, max: string, ): Promise; zrevrangebylex( key: KeyType, min: string, max: string, limit: 'LIMIT', offset: number, count: number, ): Promise; zrevrangebylex( key: KeyType, min: string, max: string, callback: Callback, ): void; zrevrangebylex( key: KeyType, min: string, max: string, limit: 'LIMIT', offset: number, count: number, callback: Callback, ): void; zcount(key: KeyType, min: number | string, max: number | string, callback: Callback): void; zcount(key: KeyType, min: number | string, max: number | string): Promise; zcard(key: KeyType, callback: Callback): void; zcard(key: KeyType): Promise; zscore(key: KeyType, member: string, callback: Callback): void; zscore(key: KeyType, member: string): Promise; zrank(key: KeyType, member: string, callback: Callback): void; zrank(key: KeyType, member: string): Promise; zrevrank(key: KeyType, member: string, callback: Callback): void; zrevrank(key: KeyType, member: string): Promise; hset(key: KeyType, field: string, value: ValueType, callback: Callback): void; hset(key: KeyType, field: string, value: ValueType): Promise; hsetBuffer(key: KeyType, field: string, value: ValueType, callback: Callback): void; hsetBuffer(key: KeyType, field: string, value: ValueType): Promise; hsetnx(key: KeyType, field: string, value: ValueType, callback: Callback): void; hsetnx(key: KeyType, field: string, value: ValueType): Promise; hget(key: KeyType, field: string, callback: Callback): void; hget(key: KeyType, field: string): Promise; hgetBuffer(key: KeyType, field: string, callback: Callback): void; hgetBuffer(key: KeyType, field: string): Promise; hmset: OverloadedKeyedHashCommand; hmget: OverloadedKeyCommand>; hincrby(key: KeyType, field: string, increment: number, callback: Callback): void; hincrby(key: KeyType, field: string, increment: number): Promise; hincrbyfloat(key: KeyType, field: string, increment: number, callback: Callback): void; hincrbyfloat(key: KeyType, field: string, increment: number): Promise; hdel: OverloadedKeyCommand; hlen(key: KeyType, callback: Callback): void; hlen(key: KeyType): Promise; hkeys(key: KeyType, callback: Callback): void; hkeys(key: KeyType): Promise; hvals(key: KeyType, callback: Callback): void; hvals(key: KeyType): Promise; hgetall(key: KeyType, callback: Callback>): void; hgetall(key: KeyType): Promise>; hexists(key: KeyType, field: string, callback: Callback): void; hexists(key: KeyType, field: string): Promise; incrby(key: KeyType, increment: number, callback: Callback): void; incrby(key: KeyType, increment: number): Promise; incrbyfloat(key: KeyType, increment: number, callback: Callback): void; incrbyfloat(key: KeyType, increment: number): Promise; decrby(key: KeyType, decrement: number, callback: Callback): void; decrby(key: KeyType, decrement: number): Promise; getset(key: KeyType, value: ValueType, callback: Callback): void; getset(key: KeyType, value: ValueType): Promise; mset: OverloadedHashCommand; msetnx: OverloadedHashCommand; randomkey(callback: Callback): void; randomkey(): Promise; select(index: number, callback: Callback): void; select(index: number): Promise; move(key: KeyType, db: string, callback: Callback): void; move(key: KeyType, db: string): Promise; rename(key: KeyType, newkey: KeyType, callback: Callback): void; rename(key: KeyType, newkey: KeyType): Promise; renamenx(key: KeyType, newkey: KeyType, callback: Callback): void; renamenx(key: KeyType, newkey: KeyType): Promise; expire(key: KeyType, seconds: number, callback: Callback): void; expire(key: KeyType, seconds: number): Promise; pexpire(key: KeyType, milliseconds: number, callback: Callback): void; pexpire(key: KeyType, milliseconds: number): Promise; expireat(key: KeyType, timestamp: number, callback: Callback): void; expireat(key: KeyType, timestamp: number): Promise; pexpireat(key: KeyType, millisecondsTimestamp: number, callback: Callback): void; pexpireat(key: KeyType, millisecondsTimestamp: number): Promise; keys(pattern: string, callback: Callback): void; keys(pattern: string): Promise; dbsize(callback: Callback): void; dbsize(): Promise; auth(username: string, password: string, callback: Callback): void; auth(password: string, callback: Callback): void; // tslint:disable-next-line unified-signatures auth(username: string, password: string): Promise; auth(password: string): Promise; ping(callback: Callback): void; ping(message: string, callback: Callback): void; ping(message?: string): Promise; echo(message: string, callback: Callback): void; echo(message: string): Promise; save(callback: Callback): void; save(): Promise; bgsave(callback: Callback): void; bgsave(): Promise; bgrewriteaof(callback: Callback): void; bgrewriteaof(): Promise; shutdown(save: 'SAVE' | 'NOSAVE', callback: Callback): void; shutdown(save: 'SAVE' | 'NOSAVE'): Promise; lastsave(callback: Callback): void; lastsave(): Promise; type(key: KeyType, callback: Callback): void; type(key: KeyType): Promise; multi(commands?: string[][], options?: MultiOptions): Pipeline; multi(options: { pipeline: false }): Promise; exec(callback: Callback>): void; exec(): Promise>; discard(callback: Callback): void; discard(): Promise; sync(callback: Callback): void; sync(): Promise; flushdb(callback: Callback): void; flushdb(): Promise; flushall(callback: Callback): void; flushall(): Promise; sort: OverloadedListCommand; info(callback: Callback): void; info(section: string, callback: Callback): void; info(section?: string): Promise; time(callback: Callback<[string, string]>): void; time(): Promise<[string, string]>; monitor(callback: Callback): void; monitor(): Promise; ttl(key: KeyType, callback: Callback): void; ttl(key: KeyType): Promise; pttl(key: KeyType, callback: Callback): void; pttl(key: KeyType): Promise; persist(key: KeyType, callback: Callback): void; persist(key: KeyType): Promise; slaveof(host: string, port: number, callback: Callback): void; slaveof(host: string, port: number): Promise; debug: OverloadedSubCommand; config(op: 'GET', cfg: string): Promise; config(op: 'GET', cfg: string, callback: Callback): void; config(op: 'REWRITE' | 'RESETSTAT'): Promise; config(op: 'REWRITE' | 'RESETSTAT', callback: Callback): void; config(op: 'SET', key: string, value: ValueType): Promise; config(op: 'SET', key: string, value: ValueType, callback: Callback): void; subscribe: OverloadedListCommand; unsubscribe: OverloadedCommand; psubscribe: OverloadedListCommand; punsubscribe: OverloadedCommand; publish(channel: string, message: string, callback: Callback): void; publish(channel: string, message: string): Promise; publishBuffer(channel: string, message: Buffer): Promise; watch: OverloadedListCommand; unwatch(callback: Callback): void; unwatch(): Promise; cluster: OverloadedSubCommand; restore: OverloadedListCommand; migrate: OverloadedListCommand; dump(key: KeyType, callback: Callback): void; dump(key: KeyType): Promise; object: OverloadedListCommand; client: OverloadedSubCommand; eval: OverloadedEvalCommand; evalsha: OverloadedEvalCommand; script: OverloadedSubCommand; quit(callback: Callback): void; quit(): Promise; scan(cursor: number | string, matchOption: 'match' | 'MATCH', pattern: string): Promise<[string, string[]]>; scan( cursor: number | string, matchOption: 'match' | 'MATCH', pattern: string, callback: Callback<[string, string[]]>, ): void; scan(cursor: number | string, countOption: 'count' | 'COUNT', count: number): Promise<[string, string[]]>; scan( cursor: number | string, countOption: 'count' | 'COUNT', count: number, callback: Callback<[string, string[]]>, ): void; scan( cursor: number | string, matchOption: 'match' | 'MATCH', pattern: string, countOption: 'count' | 'COUNT', count: number, ): Promise<[string, string[]]>; scan( cursor: number | string, matchOption: 'match' | 'MATCH', pattern: string, countOption: 'count' | 'COUNT', count: number, callback: Callback<[string, string[]]>, ): void; scan( cursor: number | string, countOption: 'count' | 'COUNT', count: number, matchOption: 'match' | 'MATCH', pattern: string, ): Promise<[string, string[]]>; scan( cursor: number | string, countOption: 'count' | 'COUNT', count: number, matchOption: 'match' | 'MATCH', pattern: string, callback: Callback<[string, string[]]>, ): void; sscan: OverloadedKeyCommand; hscan: OverloadedKeyCommand; zscan: OverloadedKeyCommand; pfmerge: OverloadedKeyCommand; pfadd: OverloadedKeyCommand; pfcount: OverloadedListCommand; pipeline(commands?: string[][]): Pipeline; scanStream(options?: ScanStreamOption): Readable; sscanStream(key: KeyType, options?: ScanStreamOption): Readable; hscanStream(key: KeyType, options?: ScanStreamOption): Readable; zscanStream(key: KeyType, options?: ScanStreamOption): Readable; xack: OverloadedKeyCommand; xadd: OverloadedKeyCommand; xclaim: OverloadedKeyCommand>; xdel: OverloadedKeyCommand; xgroup: OverloadedSubCommand; xinfo: OverloadedSubCommand; xlen(key: KeyType): Promise; xlen(key: KeyType, callback: Callback): void; xpending: OverloadedKeyCommand; xrange: OverloadedKeyCommand>; xread: OverloadedListCommand>; xreadgroup: OverloadedKeyCommand>; xrevrange: OverloadedKeyCommand>; xtrim: OverloadedKeyCommand; } interface Redis extends EventEmitter, Commander, Commands { Promise: typeof Promise; options: RedisOptions; status: string; connect(callback?: () => void): Promise; disconnect(): void; duplicate(): Redis; send_command(command: string, ...args: ValueType[]): Promise; } interface Pipeline { readonly redis: Redis; readonly isCluster: boolean; readonly options: RedisOptions; readonly length: number; bitcount(key: KeyType, callback?: Callback): Pipeline; bitcount(key: KeyType, start: number, end: number, callback?: Callback): Pipeline; get(key: KeyType, callback?: Callback): Pipeline; getBuffer(key: KeyType, callback?: Callback): Pipeline; set(key: KeyType, value: ValueType, callback?: Callback): Pipeline; set(key: KeyType, value: ValueType, setMode: string, callback?: Callback): Pipeline; set(key: KeyType, value: ValueType, expiryMode: string, time: number, callback?: Callback): Pipeline; set( key: KeyType, value: ValueType, expiryMode: string, time: number, setMode: string, callback?: Callback, ): Pipeline; setBuffer(key: KeyType, value: ValueType, callback?: Callback): Pipeline; setBuffer(key: KeyType, value: ValueType, setMode: string, callback?: Callback): Pipeline; setBuffer( key: KeyType, value: ValueType, expiryMode: string, time: number, callback?: Callback, ): Pipeline; setBuffer( key: KeyType, value: ValueType, expiryMode: string, time: number, setMode: string, callback?: Callback, ): Pipeline; setnx(key: KeyType, value: ValueType, callback?: Callback): Pipeline; setex(key: KeyType, seconds: number, value: ValueType, callback?: Callback): Pipeline; psetex(key: KeyType, milliseconds: number, value: ValueType, callback?: Callback): Pipeline; append(key: KeyType, value: ValueType, callback?: Callback): Pipeline; strlen(key: KeyType, callback?: Callback): Pipeline; del(...keys: KeyType[]): Pipeline; unlink(...keys: KeyType[]): Pipeline; exists(...keys: KeyType[]): Pipeline; setbit(key: KeyType, offset: number, value: ValueType, callback?: Callback): Pipeline; getbit(key: KeyType, offset: number, callback?: Callback): Pipeline; setrange(key: KeyType, offset: number, value: ValueType, callback?: Callback): Pipeline; getrange(key: KeyType, start: number, end: number, callback?: Callback): Pipeline; substr(key: KeyType, start: number, end: number, callback?: Callback): Pipeline; incr(key: KeyType, callback?: Callback): Pipeline; decr(key: KeyType, callback?: Callback): Pipeline; mget(...keys: KeyType[]): Pipeline; rpush(key: KeyType, ...values: ValueType[]): Pipeline; rpushBuffer(key: string, ...values: Buffer[]): Pipeline; lpush(key: KeyType, ...values: ValueType[]): Pipeline; rpushx(key: KeyType, value: ValueType, callback?: Callback): Pipeline; lpushx(key: KeyType, value: ValueType, callback?: Callback): Pipeline; linsert( key: KeyType, direction: 'BEFORE' | 'AFTER', pivot: string, value: ValueType, callback?: Callback, ): Pipeline; rpop(key: KeyType, callback?: Callback): Pipeline; lpop(key: KeyType, callback?: Callback): Pipeline; lpopBuffer(key: KeyType, callback?: Callback): Pipeline; brpop(...keys: KeyType[]): Pipeline; blpop(...keys: KeyType[]): Pipeline; brpoplpush(source: string, destination: string, timeout: number, callback?: Callback): Pipeline; llen(key: KeyType, callback?: Callback): Pipeline; lindex(key: KeyType, index: number, callback?: Callback): Pipeline; lset(key: KeyType, index: number, value: ValueType, callback?: Callback): Pipeline; lrange(key: KeyType, start: number, stop: number, callback?: Callback): Pipeline; lrangeBuffer(key: KeyType, start: number, stop: number, callback?: Callback): Pipeline; ltrim(key: KeyType, start: number, stop: number, callback?: Callback): Pipeline; lrem(key: KeyType, count: number, value: ValueType, callback?: Callback): Pipeline; rpoplpush(source: string, destination: string, callback?: Callback): Pipeline; sadd(key: KeyType, ...members: ValueType[]): Pipeline; srem(key: KeyType, ...members: ValueType[]): Pipeline; smove(source: string, destination: string, member: string, callback?: Callback): Pipeline; sismember(key: KeyType, member: string, callback?: Callback): Pipeline; scard(key: KeyType, callback?: Callback): Pipeline; spop(key: KeyType, callback?: Callback): Pipeline; spop(key: KeyType, count: number, callback?: Callback): Pipeline; srandmember(key: KeyType, callback?: Callback): Pipeline; srandmember(key: KeyType, count: number, callback?: Callback): Pipeline; sinter(...keys: KeyType[]): Pipeline; sinterstore(destination: string, ...keys: KeyType[]): Pipeline; sunion(...keys: KeyType[]): Pipeline; sunionstore(destination: string, ...keys: KeyType[]): Pipeline; sdiff(...keys: KeyType[]): Pipeline; sdiffstore(destination: string, ...keys: KeyType[]): Pipeline; smembers(key: KeyType, callback?: Callback): Pipeline; zadd(key: KeyType, ...args: string[]): Pipeline; zincrby(key: KeyType, increment: number, member: string, callback?: Callback): Pipeline; zrem(key: KeyType, ...members: ValueType[]): Pipeline; zremrangebyscore( key: KeyType, min: number | string, max: number | string, callback?: Callback, ): Pipeline; zremrangebyrank(key: KeyType, start: number, stop: number, callback?: Callback): Pipeline; zremrangebylex( key: KeyType, min: string, max: string, callback?: Callback, ): Pipeline; zunionstore(destination: string, numkeys: number, key: KeyType, ...args: string[]): Pipeline; zinterstore(destination: string, numkeys: number, key: KeyType, ...args: string[]): Pipeline; zrange(key: KeyType, start: number, stop: number, callback?: Callback): Pipeline; zrange( key: KeyType, start: number, stop: number, withScores: 'WITHSCORES', callback?: Callback, ): Pipeline; zrevrange(key: KeyType, start: number, stop: number, callback?: Callback): Pipeline; zrevrange( key: KeyType, start: number, stop: number, withScores: 'WITHSCORES', callback?: Callback, ): Pipeline; zrangebyscore(key: KeyType, min: number | string, max: number | string, ...args: string[]): Pipeline; zrevrangebyscore(key: KeyType, max: number | string, min: number | string, ...args: string[]): Pipeline; zrangebylex( key: KeyType, min: string, max: string, callback?: Callback, ): Pipeline; zrangebylex( key: KeyType, min: string, max: string, limit: 'LIMIT', offset: number, count: number, callback?: Callback, ): Pipeline; zrevrangebylex( key: KeyType, min: string, max: string, callback?: Callback, ): Pipeline; zrevrangebylex( key: KeyType, min: string, max: string, limit: 'LIMIT', offset: number, count: number, callback?: Callback, ): Pipeline; zcount(key: KeyType, min: number | string, max: number | string, callback?: Callback): Pipeline; zcard(key: KeyType, callback?: Callback): Pipeline; zscore(key: KeyType, member: string, callback?: Callback): Pipeline; zrank(key: KeyType, member: string, callback?: Callback): Pipeline; zrevrank(key: KeyType, member: string, callback?: Callback): Pipeline; hset(key: KeyType, field: string, value: ValueType, callback?: Callback): Pipeline; hsetBuffer(key: KeyType, field: string, value: ValueType, callback?: Callback): Pipeline; hsetnx(key: KeyType, field: string, value: ValueType, callback?: Callback): Pipeline; hget(key: KeyType, field: string, callback?: Callback): Pipeline; hgetBuffer(key: KeyType, field: string, callback?: Callback): Pipeline; hmset(key: KeyType, ...args: ValueType[]): Pipeline; hmset(key: KeyType, data: object | Map, callback?: Callback): Pipeline; hmget(key: KeyType, ...fields: string[]): Pipeline; hincrby(key: KeyType, field: string, increment: number, callback?: Callback): Pipeline; hincrbyfloat(key: KeyType, field: string, increment: number, callback?: Callback): Pipeline; hdel(key: KeyType, ...fields: string[]): Pipeline; hlen(key: KeyType, callback?: Callback): Pipeline; hkeys(key: KeyType, callback?: Callback): Pipeline; hvals(key: KeyType, callback?: Callback): Pipeline; hgetall(key: KeyType, callback?: Callback>): Pipeline; hexists(key: KeyType, field: string, callback?: Callback): Pipeline; incrby(key: KeyType, increment: number, callback?: Callback): Pipeline; incrbyfloat(key: KeyType, increment: number, callback?: Callback): Pipeline; decrby(key: KeyType, decrement: number, callback?: Callback): Pipeline; getset(key: KeyType, value: ValueType, callback?: Callback): Pipeline; mset(...args: ValueType[]): Pipeline; mset(data: object | Map, callback?: Callback): Pipeline; msetnx(...args: ValueType[]): Pipeline; msetnx(data: object | Map, callback?: Callback): Pipeline; randomkey(callback?: Callback): Pipeline; select(index: number, callback?: Callback): Pipeline; move(key: KeyType, db: string, callback?: Callback): Pipeline; rename(key: KeyType, newkey: KeyType, callback?: Callback): Pipeline; renamenx(key: KeyType, newkey: KeyType, callback?: Callback): Pipeline; expire(key: KeyType, seconds: number, callback?: Callback): Pipeline; pexpire(key: KeyType, milliseconds: number, callback?: Callback): Pipeline; expireat(key: KeyType, timestamp: number, callback?: Callback): Pipeline; pexpireat(key: KeyType, millisecondsTimestamp: number, callback?: Callback): Pipeline; keys(pattern: string, callback?: Callback): Pipeline; dbsize(callback?: Callback): Pipeline; auth(password: string, callback?: Callback): Pipeline; auth(username: string, password: string, callback?: Callback): Pipeline; ping(callback?: Callback): Pipeline; ping(message: string, callback?: Callback): Pipeline; echo(message: string, callback?: Callback): Pipeline; save(callback?: Callback): Pipeline; bgsave(callback?: Callback): Pipeline; bgrewriteaof(callback?: Callback): Pipeline; shutdown(save: 'SAVE' | 'NOSAVE', callback?: Callback): Pipeline; lastsave(callback?: Callback): Pipeline; type(key: KeyType, callback?: Callback): Pipeline; multi(callback?: Callback): Pipeline; exec(callback?: Callback>): Promise>; discard(callback?: Callback): Pipeline; sync(callback?: Callback): Pipeline; flushdb(callback?: Callback): Pipeline; flushall(callback?: Callback): Pipeline; sort(key: KeyType, ...args: string[]): Pipeline; info(callback?: Callback): Pipeline; info(section: string, callback?: Callback): Pipeline; time(callback?: Callback<[string, string]>): Pipeline; monitor(callback?: Callback): Pipeline; ttl(key: KeyType, callback?: Callback): Pipeline; pttl(key: KeyType, callback?: Callback): Pipeline; persist(key: KeyType, callback?: Callback): Pipeline; slaveof(host: string, port: number, callback?: Callback): Pipeline; debug(...args: ValueType[]): Pipeline; config(...args: ValueType[]): Pipeline; subscribe(...channels: ValueType[]): Pipeline; unsubscribe(...channels: string[]): Pipeline; psubscribe(...patterns: string[]): Pipeline; punsubscribe(...patterns: string[]): Pipeline; publish(channel: string, message: string, callback?: Callback): Pipeline; watch(...keys: KeyType[]): Pipeline; unwatch(callback?: Callback): Pipeline; cluster(...args: ValueType[]): Pipeline; restore(...args: ValueType[]): Pipeline; migrate(...args: ValueType[]): Pipeline; dump(key: KeyType, callback?: Callback): Pipeline; object(subcommand: string, ...args: ValueType[]): Pipeline; client(...args: ValueType[]): Pipeline; eval(script: string, numKeys: number, ...args: ValueType[]): Pipeline; evalsha(scriptSha: string, numKeys: string, ...args: ValueType[]): Pipeline; script(...args: ValueType[]): Pipeline; quit(callback?: Callback): Pipeline; scan(cursor: number | string): Pipeline; scan(cursor: number | string, matchOption: 'match' | 'MATCH', pattern: string): Pipeline; scan(cursor: number | string, countOption: 'count' | 'COUNT', count: number): Pipeline; scan( cursor: number | string, matchOption: 'match' | 'MATCH', pattern: string, countOption: 'count' | 'COUNT', count: number, ): Pipeline; scan( cursor: number | string, countOption: 'count' | 'COUNT', count: number, matchOption: 'match' | 'MATCH', pattern: string, ): Pipeline; sscan(key: KeyType, cursor: number, ...args: ValueType[]): Pipeline; hscan(key: KeyType, cursor: number, ...args: ValueType[]): Pipeline; zscan(key: KeyType, cursor: number, ...args: ValueType[]): Pipeline; pfmerge(destkey: KeyType, ...sourcekeys: KeyType[]): Pipeline; pfadd(key: KeyType, ...elements: string[]): Pipeline; pfcount(...keys: KeyType[]): Pipeline; xack(key: KeyType, group: string, ...ids: string[]): Pipeline; xadd(key: KeyType, id: string, ...args: string[]): Pipeline; xclaim( key: KeyType, group: string, consumer: string, minIdleTime: number, id: string, ...args: ValueType[] ): Pipeline; xdel(key: KeyType, ...ids: string[]): Pipeline; xgroup(...args: ValueType[]): Pipeline; xinfo(...args: ValueType[]): Pipeline; xlen(key: KeyType): Pipeline; xpending(key: KeyType, group: string, ...args: ValueType[]): Pipeline; xrange(key: KeyType, start: string, end: string, ...args: ValueType[]): Pipeline; xread(...args: ValueType[]): Pipeline; xreadgroup(command: 'GROUP' | 'group', group: string, consumer: string, ...args: ValueType[]): Pipeline; xrevrange(key: KeyType, end: string, start: string, ...args: ValueType[]): Pipeline; xtrim(key: KeyType, strategy: 'MAXLEN' | 'maxlen', ...args: ValueType[]): Pipeline; } interface NodeConfiguration { host?: string; port?: number; } type ClusterNode = string | number | NodeConfiguration; type NodeRole = 'master' | 'slave' | 'all'; type CallbackFunction = (err?: NodeJS.ErrnoException | null, result?: T) => void; type Ok = 'OK'; interface Cluster extends EventEmitter, Commander, Commands { connect(): Promise; disconnect(): void; nodes(role?: NodeRole): Redis[]; } interface ClusterStatic extends EventEmitter { new (nodes: ClusterNode[], options?: ClusterOptions): Cluster; } interface RedisOptions { port?: number; host?: string; /** * 4 (IPv4) or 6 (IPv6), Defaults to 4. */ family?: number; /** * Local domain socket path. If set the port, host and family will be ignored. */ path?: string; /** * TCP KeepAlive on the socket with a X ms delay before start. Set to a non-number value to disable keepAlive. */ keepAlive?: number; connectionName?: string; /** * If set, client will send AUTH command with the value of this option as the first argument when connected. The `password` option must be set too. Username should only be set for Redis >=6. */ username?: string; /** * If set, client will send AUTH command with the value of this option when connected. */ password?: string; /** * Database index to use. */ db?: number; /** * When a connection is established to the Redis server, the server might still be loading * the database from disk. While loading, the server not respond to any commands. * To work around this, when this option is true, ioredis will check the status of the Redis server, * and when the Redis server is able to process commands, a ready event will be emitted. */ enableReadyCheck?: boolean; keyPrefix?: string; /** * When the return value isn't a number, ioredis will stop trying to reconnect. * Fixed in: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/15858 */ retryStrategy?(times: number): number | void | null; /** * By default, all pending commands will be flushed with an error every * 20 retry attempts. That makes sure commands won't wait forever when * the connection is down. You can change this behavior by setting * `maxRetriesPerRequest`. * * Set maxRetriesPerRequest to `null` to disable this behavior, and * every command will wait forever until the connection is alive again * (which is the default behavior before ioredis v4). */ maxRetriesPerRequest?: number | null; /** * 1/true means reconnect, 2 means reconnect and resend failed command. Returning false will ignore * the error and do nothing. */ reconnectOnError?(error: Error): boolean | 1 | 2; /** * By default, if there is no active connection to the Redis server, commands are added to a queue * and are executed once the connection is "ready" (when enableReadyCheck is true, "ready" means * the Redis server has loaded the database from disk, otherwise means the connection to the Redis * server has been established). If this option is false, when execute the command when the connection * isn't ready, an error will be returned. */ enableOfflineQueue?: boolean; /** * The milliseconds before a timeout occurs during the initial connection to the Redis server. * default: 10000. */ connectTimeout?: number; /** * After reconnected, if the previous connection was in the subscriber mode, client will auto re-subscribe these channels. * default: true. */ autoResubscribe?: boolean; /** * If true, client will resend unfulfilled commands(e.g. block commands) in the previous connection when reconnected. * default: true. */ autoResendUnfulfilledCommands?: boolean; lazyConnect?: boolean; tls?: ConnectionOptions; /** * default: "master". */ role?: 'master' | 'slave'; /** * default: null. */ name?: string; sentinelUsername?: string; sentinelPassword?: string; sentinels?: Array<{ host: string; port: number }>; /** * If `sentinelRetryStrategy` returns a valid delay time, ioredis will try to reconnect from scratch. * default: function(times) { return Math.min(times * 10, 1000); } */ sentinelRetryStrategy?(times: number): number | void | null; /** * Can be used to prefer a particular slave or set of slaves based on priority. */ preferredSlaves?: PreferredSlaves; /** * Whether to support the `tls` option when connecting to Redis via sentinel mode. * default: false. */ enableTLSForSentinelMode?: boolean; sentinelTLS?: SecureContextOptions; /** * NAT map for sentinel connector. * default: null. */ natMap?: NatMap; /** * Update the given `sentinels` list with new IP addresses when communicating with existing sentinels. * default: true. */ updateSentinels?: boolean; /** * Enable READONLY mode for the connection. Only available for cluster mode. * default: false. */ readOnly?: boolean; /** * If you are using the hiredis parser, it's highly recommended to enable this option. * Create another instance with dropBufferSupport disabled for other commands that you want to return binary instead of string */ dropBufferSupport?: boolean; /** * Whether to show a friendly error stack. Will decrease the performance significantly. */ showFriendlyErrorStack?: boolean; } interface AddressFromResponse { port: string; ip: string; flags?: string; } type PreferredSlaves = | ((slaves: AddressFromResponse[]) => AddressFromResponse | null) | Array<{ port: string; ip: string; prio?: number }> | { port: string; ip: string; prio?: number }; type SecureVersion = 'TLSv1.3' | 'TLSv1.2' | 'TLSv1.1' | 'TLSv1'; interface SecureContextOptions { pfx?: string | Buffer | Array; key?: string | Buffer | Array; passphrase?: string; cert?: string | Buffer | Array; ca?: string | Buffer | Array; ciphers?: string; honorCipherOrder?: boolean; ecdhCurve?: string; clientCertEngine?: string; crl?: string | Buffer | Array; dhparam?: string | Buffer; secureOptions?: number; // Value is a numeric bitmask of the `SSL_OP_*` options secureProtocol?: string; // SSL Method, e.g. SSLv23_method sessionIdContext?: string; /** * Optionally set the maximum TLS version to allow. One * of `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. Cannot be specified along with the * `secureProtocol` option, use one or the other. * **Default:** `'TLSv1.3'`, unless changed using CLI options. Using * `--tls-max-v1.2` sets the default to `'TLSv1.2'`. Using `--tls-max-v1.3` sets the default to * `'TLSv1.3'`. If multiple of the options are provided, the highest maximum is used. */ maxVersion?: SecureVersion; /** * Optionally set the minimum TLS version to allow. One * of `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. Cannot be specified along with the * `secureProtocol` option, use one or the other. It is not recommended to use * less than TLSv1.2, but it may be required for interoperability. * **Default:** `'TLSv1.2'`, unless changed using CLI options. Using * `--tls-v1.0` sets the default to `'TLSv1'`. Using `--tls-v1.1` sets the default to * `'TLSv1.1'`. Using `--tls-min-v1.3` sets the default to * 'TLSv1.3'. If multiple of the options are provided, the lowest minimum is used. */ minVersion?: SecureVersion; } interface ScanStreamOption { match?: string; count?: number; } type DNSLookupFunction = ( hostname: string, callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void, ) => void; interface NatMap { [key: string]: { host: string; port: number }; } interface ClusterOptions { clusterRetryStrategy?(times: number, reason?: Error): number | null; enableOfflineQueue?: boolean; enableReadyCheck?: boolean; scaleReads?: string; maxRedirections?: number; retryDelayOnFailover?: number; retryDelayOnClusterDown?: number; retryDelayOnTryAgain?: number; slotsRefreshTimeout?: number; slotsRefreshInterval?: number; redisOptions?: RedisOptions; lazyConnect?: boolean; dnsLookup?: DNSLookupFunction; natMap?: NatMap; } interface MultiOptions { pipeline: boolean; } }