From 341ff81e331ac12a7453fcc483b53ac587139dae Mon Sep 17 00:00:00 2001 From: Dmitry Motovilov Date: Fri, 5 Oct 2018 21:06:48 +0300 Subject: [PATCH] [ioredis] improve scan() function types (#29451) --- types/ioredis/index.d.ts | 16 ++++++++++++++-- types/ioredis/ioredis-tests.ts | 12 ++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/types/ioredis/index.d.ts b/types/ioredis/index.d.ts index bb03f10a6c..6f50ab0ee6 100644 --- a/types/ioredis/index.d.ts +++ b/types/ioredis/index.d.ts @@ -7,6 +7,7 @@ // Shahar Mor // Whemoon Jang // Francis Gulotta +// Dmitry Motovilov // Oleg Repin // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 @@ -455,7 +456,13 @@ declare namespace IORedis { quit(callback: (err: Error, res: string) => void): void; quit(): Promise; - scan(cursor: number, ...args: any[]): any; + scan(cursor: number): Promise<[string, string[]]>; + + scan(cursor: number, matchOption: 'match' | 'MATCH', pattern: string): Promise<[string, string[]]>; + scan(cursor: number, countOption: 'count' | 'COUNT', count: number): Promise<[string, string[]]>; + + scan(cursor: number, matchOption: 'match' | 'MATCH', pattern: string, countOption: 'count' | 'COUNT', count: number): Promise<[string, string[]]>; + scan(cursor: number, countOption: 'count' | 'COUNT', count: number, matchOption: 'match' | 'MATCH', pattern: string): Promise<[string, string[]]>; sscan(key: KeyType, cursor: number, ...args: any[]): any; @@ -776,8 +783,13 @@ declare namespace IORedis { quit(callback?: (err: Error, res: string) => void): Pipeline; - scan(cursor: number, ...args: any[]): Pipeline; + scan(cursor: number): Pipeline; + scan(cursor: number, matchOption: 'match' | 'MATCH', pattern: string): Pipeline; + scan(cursor: number, countOption: 'count' | 'COUNT', count: number): Pipeline; + + scan(cursor: number, matchOption: 'match' | 'MATCH', pattern: string, countOption: 'count' | 'COUNT', count: number): Pipeline; + scan(cursor: number, countOption: 'count' | 'COUNT', count: number, matchOption: 'match' | 'MATCH', pattern: string): Pipeline; sscan(key: KeyType, cursor: number, ...args: any[]): Pipeline; hscan(key: KeyType, cursor: number, ...args: any[]): Pipeline; diff --git a/types/ioredis/ioredis-tests.ts b/types/ioredis/ioredis-tests.ts index fa1edcdb30..82b5ec4d12 100644 --- a/types/ioredis/ioredis-tests.ts +++ b/types/ioredis/ioredis-tests.ts @@ -124,6 +124,18 @@ Redis.Command.setReplyTransformer('get', (result: any) => { return result; }); +redis.scan(0, 'match', '*foo*', 'count', 20).then(([nextCursor, keys]) => { + // nextCursor is always a string + if (nextCursor === '0') { + // keys is always an array of strings and it might be empty + return keys.map(key => key.trim()); + } +}); + +redis.pipeline().scan(0, 'count', 20, 'match', '*foo*').exec((err, result) => { + // result = [[null, [nextCursor, keys]]] +}); + // multi redis.multi().set('foo', 'bar').set('foo', 'baz').get('foo', (err, result) => { // result === 'QUEUED'