mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 20:40:20 +00:00
[ioredis] improve scan() function types (#29451)
This commit is contained in:
committed by
Wesley Wigham
parent
d2107afbb9
commit
341ff81e33
Vendored
+14
-2
@@ -7,6 +7,7 @@
|
||||
// Shahar Mor <https://github.com/shaharmor>
|
||||
// Whemoon Jang <https://github.com/palindrom615>
|
||||
// Francis Gulotta <https://github.com/reconbot>
|
||||
// Dmitry Motovilov <https://github.com/funthing>
|
||||
// Oleg Repin <https://github.com/iamolegga>
|
||||
// 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<string>;
|
||||
|
||||
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;
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user