diff --git a/types/ioredis/index.d.ts b/types/ioredis/index.d.ts index 99c99dcf04..869dc364c9 100644 --- a/types/ioredis/index.d.ts +++ b/types/ioredis/index.d.ts @@ -875,10 +875,20 @@ declare namespace IORedis { type NodeRole = 'master' | 'slave' | 'all'; + type CallbackFunction = (err?: NodeJS.ErrnoException | null, result?: T) => void; + interface Cluster extends NodeJS.EventEmitter, Commander { connect(callback: () => void): Promise; disconnect(): void; nodes(role?: NodeRole): Redis[]; + quit(callback?: CallbackFunction<'OK'>): Promise<'OK'>; + get(key: KeyType, callback: (err: Error, res: string | null) => void): void; + get(key: KeyType): Promise; + set(key: KeyType, value: any, expiryMode?: string | any[], time?: number | string, setMode?: number | string): Promise; + set(key: KeyType, value: any, callback: (err: Error, res: string) => void): void; + set(key: KeyType, value: any, setMode: string | any[], callback: (err: Error, res: string) => void): void; + set(key: KeyType, value: any, expiryMode: string, time: number | string, callback: (err: Error, res: string) => void): void; + set(key: KeyType, value: any, expiryMode: string, time: number | string, setMode: number | string, callback: (err: Error, res: string) => void): void; } interface ClusterStatic extends NodeJS.EventEmitter, Commander { diff --git a/types/ioredis/ioredis-tests.ts b/types/ioredis/ioredis-tests.ts index f3cafe1f18..57ee06a5f3 100644 --- a/types/ioredis/ioredis-tests.ts +++ b/types/ioredis/ioredis-tests.ts @@ -226,3 +226,32 @@ cluster.nodes().map(node => { .exec() .then(result => console.log(result)); }); +cluster.set('foo', 'bar'); +cluster.get('foo', (err, result) => { + if (err) { + console.error(err); + } + console.log(result); +}); +cluster.get('foo') + .then(result => console.log(result)) + .catch(reason => console.error(reason)); +cluster.connect(() => { + console.log('connect'); +}) +.then(result => console.log(result)) +.then(reason => console.error(reason)); +cluster.disconnect(); +cluster.quit(result => { + console.log(result); +}); +const getBuiltinCommandsResult = cluster.getBuiltinCommands(); +console.log(getBuiltinCommandsResult); +const createBuiltinCommandResult = cluster.createBuiltinCommand('createBuiltinCommand'); +console.log(createBuiltinCommandResult); +const defineCommandResult = cluster.defineCommand('defineCommand', { + numberOfKeys: 1, + lua: 'lua' +}); +console.log(defineCommandResult); +cluster.sendCommand();