From 33698bbac399c50504b0108c725673307333de98 Mon Sep 17 00:00:00 2001 From: Francis Gulotta Date: Mon, 6 Aug 2018 15:00:56 -0400 Subject: [PATCH] ioredis: add some missing overloads and methods (#27870) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added the following for base redis and pipeline methods - Corrected the `set()` method’s arguments and returns - added the `setBuffer()` method - added the `hsetBuffer()` method - added the `hgetBuffer()` method --- types/ioredis/index.d.ts | 32 ++++++++++++++++++++++++++++++-- types/ioredis/ioredis-tests.ts | 19 ++++++++++++++++++- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/types/ioredis/index.d.ts b/types/ioredis/index.d.ts index 45b334a205..e593f4dcc3 100644 --- a/types/ioredis/index.d.ts +++ b/types/ioredis/index.d.ts @@ -6,6 +6,7 @@ // Ebrahim // Shahar Mor // Whemoon Jang +// Francis Gulotta // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 @@ -65,10 +66,23 @@ declare namespace IORedis { get(key: string, callback: (err: Error, res: string) => void): void; get(key: string): Promise; + getBuffer(key: string, callback: (err: Error, res: Buffer) => void): void; getBuffer(key: string): Promise; - set(key: string, value: any, ...args: any[]): any; + set(key: string, value: any, expiryMode?: string | any[], time?: number | string, setMode?: number | string): Promise; + + set(key: string, value: any, callback: (err: Error, res: string) => void): void; + set(key: string, value: any, setMode: string | any[], callback: (err: Error, res: string) => void): void; + set(key: string, value: any, expiryMode: string, time: number | string, callback: (err: Error, res: string) => void): void; + set(key: string, value: any, expiryMode: string, time: number | string, setMode: number | string, callback: (err: Error, res: string) => void): void; + + setBuffer(key: string, value: any, expiryMode?: string | any[], time?: number | string, setMode?: number | string): Promise; + + setBuffer(key: string, value: any, callback: (err: Error, res: Buffer) => void): void; + setBuffer(key: string, value: any, setMode: string, callback: (err: Error, res: Buffer) => void): void; + setBuffer(key: string, value: any, expiryMode: string, time: number, callback: (err: Error, res: Buffer) => void): void; + setBuffer(key: string, value: any, expiryMode: string, time: number | string, setMode: number | string, callback: (err: Error, res: Buffer) => void): void; setnx(key: string, value: any, callback: (err: Error, res: any) => void): void; setnx(key: string, value: any): Promise; @@ -241,12 +255,16 @@ declare namespace IORedis { hset(key: string, field: string, value: any, callback: (err: Error, res: 0 | 1) => void): void; hset(key: string, field: string, value: any): Promise<0 | 1>; + hsetBuffer(key: string, field: string, value: any, callback: (err: Error, res: 0 | 1) => void): void; + hsetBuffer(key: string, field: string, value: any): Promise; hsetnx(key: string, field: string, value: any, callback: (err: Error, res: 0 | 1) => void): void; hsetnx(key: string, field: string, value: any): Promise<0 | 1>; hget(key: string, field: string, callback: (err: Error, res: string) => void): void; hget(key: string, field: string): Promise; + hgetBuffer(key: string, field: string, callback: (err: Error, res: Buffer) => void): void; + hgetBuffer(key: string, field: string): Promise; hmset(key: string, field: string, value: any, ...args: string[]): Promise<0 | 1>; hmset(key: string, data: any, callback: (err: Error, res: 0 | 1) => void): void; @@ -471,7 +489,15 @@ declare namespace IORedis { get(key: string, callback?: (err: Error, res: string) => void): Pipeline; getBuffer(key: string, callback?: (err: Error, res: Buffer) => void): Pipeline; - set(key: string, value: any, ...args: any[]): Pipeline; + set(key: string, value: any, callback?: (err: Error, res: string) => void): Pipeline; + set(key: string, value: any, setMode: string, callback?: (err: Error, res: string) => void): Pipeline; + set(key: string, value: any, expiryMode: string, time: number, callback?: (err: Error, res: string) => void): Pipeline; + set(key: string, value: any, expiryMode: string, time: number, setMode: string, callback?: (err: Error, res: string) => void): Pipeline; + + setBuffer(key: string, value: any, callback?: (err: Error, res: Buffer) => void): Pipeline; + setBuffer(key: string, value: any, setMode: string, callback?: (err: Error, res: Buffer) => void): Pipeline; + setBuffer(key: string, value: any, expiryMode: string, time: number, callback?: (err: Error, res: Buffer) => void): Pipeline; + setBuffer(key: string, value: any, expiryMode: string, time: number, setMode: string, callback?: (err: Error, res: Buffer) => void): Pipeline; setnx(key: string, value: any, callback?: (err: Error, res: any) => void): Pipeline; @@ -602,10 +628,12 @@ declare namespace IORedis { zrevrank(key: string, member: string, callback?: (err: Error, res: number) => void): Pipeline; hset(key: string, field: string, value: any, callback?: (err: Error, res: 0 | 1) => void): Pipeline; + hsetBuffer(key: string, field: string, value: any, callback?: (err: Error, res: Buffer) => void): Pipeline; hsetnx(key: string, field: string, value: any, callback?: (err: Error, res: 0 | 1) => void): Pipeline; hget(key: string, field: string, callback?: (err: Error, res: string) => void): Pipeline; + hgetBuffer(key: string, field: string, callback?: (err: Error, res: Buffer) => void): Pipeline; hmset(key: string, field: string, value: any, ...args: string[]): Pipeline; hmset(key: string, data: any, callback?: (err: Error, res: 0 | 1) => void): Pipeline; diff --git a/types/ioredis/ioredis-tests.ts b/types/ioredis/ioredis-tests.ts index 7dd98879a5..32ae5c24d5 100644 --- a/types/ioredis/ioredis-tests.ts +++ b/types/ioredis/ioredis-tests.ts @@ -16,7 +16,20 @@ redis.sadd('set', 1, 3, 5, 7); redis.sadd('set', [1, 3, 5, 7]); // All arguments are passed directly to the redis server: -redis.set('key', '100', 'EX', 10); +redis.set('key', '100'); +redis.set('key', '100', 'XX'); +redis.set('key', '100', 'PX', 10); +redis.set('key', '100', 'EX', 10, 'NX'); +redis.set('key', '100', 'NX', 'EX', 10); +redis.set('key', '100', ['EX', 10, 'NX']); +redis.setBuffer('key', '100', 'NX', 'EX', 10); + +redis.set('key', '100', (err, data) => {}); +redis.set('key', '100', 'XX', (err, data) => {}); +redis.set('key', '100', 'PX', 10, (err, data) => {}); +redis.set('key', '100', 'EX', 10, 'NX', (err, data) => {}); +redis.set('key', '100', ['EX', 10, 'NX'], (err, data) => {}); +redis.setBuffer('key', '100', 'NX', 'EX', 10, (err, data) => {}); new Redis(); // Connect to 127.0.0.1:6379 new Redis(6380); // 127.0.0.1:6380 @@ -59,6 +72,10 @@ redis.on('messageBuffer', (channel: any, message: any) => { const pipeline = redis.pipeline(); pipeline.set('foo', 'bar'); pipeline.del('cc'); +pipeline.hset('hash', 'foo', 4); +pipeline.hget('hash', 'foo'); +pipeline.hsetBuffer('hash', 'fooBuffer', 4); +pipeline.hgetBuffer('hash', 'fooBuffer'); pipeline.exec((err, results) => { // `err` is always null, and `results` is an array of responses // corresponding to the sequence of queued commands.