[ioredis] Added typings for publishBuffer and zaddBuffer (#38075)

* 🏷 Added the publishBuffer(string, Buffer): Promise<number> typings to ioredis

* 🏷 Added the zaddBuffer(KeyType, string, Buffer): Promise<string | number> 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<string | number>
This commit is contained in:
Maarten Tielemans
2019-09-04 02:11:50 +02:00
committed by Ron Buckton
parent f39b36b2e7
commit 8afe8277bf
4 changed files with 18 additions and 2 deletions

View File

@@ -226,6 +226,8 @@ declare namespace IORedis {
zadd(key: KeyType, ...args: string[]): Promise<number | string>;
zaddBuffer(key: KeyType, score1: number, member1: Buffer): Promise<string | number>;
zincrby(key: KeyType, increment: number, member: string, callback: (err: Error, res: any) => void): void;
zincrby(key: KeyType, increment: number, member: string): Promise<any>;
@@ -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<number>;
publishBuffer(channel: string, message: Buffer): Promise<number>;
watch(...keys: KeyType[]): any;
unwatch(callback: (err: Error, res: string) => void): void;

View File

@@ -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
});

View File

@@ -221,6 +221,8 @@ declare namespace IORedis {
zadd(key: string, ...args: string[]): any;
zaddBuffer(key: string, score1: number, member1: Buffer): Promise<string | number>;
zincrby(key: string, increment: number, member: string, callback: (err: Error, res: any) => void): void;
zincrby(key: string, increment: number, member: string): Promise<any>;
@@ -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<number>;
publishBuffer(channel: string, message: Buffer): Promise<number>;
watch(...keys: string[]): any;
unwatch(callback: (err: Error, res: string) => void): void;

View File

@@ -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
});