diff --git a/types/ioredis/index.d.ts b/types/ioredis/index.d.ts index 33b4ab8f8d..24678e4d43 100644 --- a/types/ioredis/index.d.ts +++ b/types/ioredis/index.d.ts @@ -36,7 +36,7 @@ interface RedisStatic { (host?: string, options?: IORedis.RedisOptions): IORedis.Redis; (options?: IORedis.RedisOptions): IORedis.Redis; Cluster: IORedis.ClusterStatic; - Command: IORedis.Command; + Command: typeof Command; } declare var IORedis: RedisStatic; @@ -55,6 +55,29 @@ declare class Commander { 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 KeyType = string | Buffer; @@ -62,10 +85,7 @@ declare namespace IORedis { type ValueType = string | Buffer | number | any[]; - interface Command { - setArgumentTransformer(name: string, fn: (args: ValueType[]) => ValueType[]): void; - setReplyTransformer(name: string, fn: (result: any) => any): void; - } + type Command = _Command; interface Redis extends EventEmitter, Commander { Promise: typeof Promise; diff --git a/types/ioredis/ioredis-tests.ts b/types/ioredis/ioredis-tests.ts index 8e65590846..cd19f613c0 100644 --- a/types/ioredis/ioredis-tests.ts +++ b/types/ioredis/ioredis-tests.ts @@ -1,4 +1,5 @@ import Redis = require("ioredis"); +import { Command } from "ioredis"; const redis = new Redis(); @@ -334,3 +335,6 @@ cluster.sendCommand(); redis.zaddBuffer('foo', 1, Buffer.from('bar')).then(() => { // sorted set 'foo' now has score 'foo1' containing barBuffer }); + +new Command('mget', ['key1', 'key2']); +new Command('get', ['key2'], { replyEncoding: 'utf8' });