From 8afe8277bfa7de3a629c2bb35011e034a2249e47 Mon Sep 17 00:00:00 2001 From: Maarten Tielemans Date: Wed, 4 Sep 2019 02:11:50 +0200 Subject: [PATCH] [ioredis] Added typings for publishBuffer and zaddBuffer (#38075) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🏷 Added the publishBuffer(string, Buffer): Promise typings to ioredis * 🏷 Added the zaddBuffer(KeyType, string, Buffer): Promise typings to ioredis * ✅ Added primitive tests for publishBuffer and zaddBuffer * ♻ Refactorred ioredis zaddBuffer tests to get rid of const * 🐛 Changed the type of zaddBuffer to zaddBuffer(string, number, Buffer): Promise --- types/ioredis/index.d.ts | 4 ++++ types/ioredis/ioredis-tests.ts | 6 +++++- types/ioredis/v3/index.d.ts | 4 ++++ types/ioredis/v3/ioredis-tests.ts | 6 +++++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/types/ioredis/index.d.ts b/types/ioredis/index.d.ts index 0e348ea430..b9937fc390 100644 --- a/types/ioredis/index.d.ts +++ b/types/ioredis/index.d.ts @@ -226,6 +226,8 @@ declare namespace IORedis { zadd(key: KeyType, ...args: string[]): Promise; + zaddBuffer(key: KeyType, score1: number, member1: Buffer): Promise; + zincrby(key: KeyType, increment: number, member: string, callback: (err: Error, res: any) => void): void; zincrby(key: KeyType, increment: number, member: string): Promise; @@ -448,6 +450,8 @@ declare namespace IORedis { publish(channel: string, message: string, callback: (err: Error, res: number) => void): void; publish(channel: string, message: string): Promise; + publishBuffer(channel: string, message: Buffer): Promise; + watch(...keys: KeyType[]): any; unwatch(callback: (err: Error, res: string) => void): void; diff --git a/types/ioredis/ioredis-tests.ts b/types/ioredis/ioredis-tests.ts index da6681ab65..4b6d2b0da9 100644 --- a/types/ioredis/ioredis-tests.ts +++ b/types/ioredis/ioredis-tests.ts @@ -85,7 +85,7 @@ redis.subscribe('news', 'music', (err: any, count: any) => { // `count` represents the number of channels we are currently subscribed to. pub.publish('news', 'Hello world!'); - pub.publish('music', 'Hello again!'); + pub.publishBuffer('music', Buffer.from('Hello again!')); }); redis.on('message', (channel: any, message: any) => { @@ -272,3 +272,7 @@ const defineCommandResult = cluster.defineCommand('defineCommand', { }); console.log(defineCommandResult); cluster.sendCommand(); + +redis.zaddBuffer('foo', 1, Buffer.from('bar')).then(() => { + // sorted set 'foo' now has score 'foo1' containing barBuffer +}); diff --git a/types/ioredis/v3/index.d.ts b/types/ioredis/v3/index.d.ts index c58a1d16cc..cf164ee769 100644 --- a/types/ioredis/v3/index.d.ts +++ b/types/ioredis/v3/index.d.ts @@ -221,6 +221,8 @@ declare namespace IORedis { zadd(key: string, ...args: string[]): any; + zaddBuffer(key: string, score1: number, member1: Buffer): Promise; + zincrby(key: string, increment: number, member: string, callback: (err: Error, res: any) => void): void; zincrby(key: string, increment: number, member: string): Promise; @@ -439,6 +441,8 @@ declare namespace IORedis { publish(channel: string, message: string, callback: (err: Error, res: number) => void): void; publish(channel: string, message: string): Promise; + publishBuffer(channel: string, message: Buffer): Promise; + watch(...keys: string[]): any; unwatch(callback: (err: Error, res: string) => void): void; diff --git a/types/ioredis/v3/ioredis-tests.ts b/types/ioredis/v3/ioredis-tests.ts index b2ac8e6de0..f05ed73114 100644 --- a/types/ioredis/v3/ioredis-tests.ts +++ b/types/ioredis/v3/ioredis-tests.ts @@ -74,7 +74,7 @@ redis.subscribe('news', 'music', (err: any, count: any) => { // `count` represents the number of channels we are currently subscribed to. pub.publish('news', 'Hello world!'); - pub.publish('music', 'Hello again!'); + pub.publishBuffer('music', Buffer.from('Hello again!')); }); redis.on('message', (channel: any, message: any) => { @@ -180,3 +180,7 @@ new Redis.Cluster([], { new Redis.Cluster([], { clusterRetryStrategy: (times: number) => 1 }); + +redis.zaddBuffer('foo', 1, Buffer.from('bar')).then(() => { + // sorted set 'foo' now has score 'foo1' containing barBuffer +});