[redis] Fix types for hmset and flushdb commands. Fix tslint callable-types error (#31550)

* [redis] fix type of result in callback for hmset and flushdb commands

* [redis] fix tslint callable-types error for RedisClient and Multi
This commit is contained in:
Stanislav Dzhus
2018-12-20 08:19:11 -08:00
committed by Nathan Shively-Sanders
parent b2716db969
commit cbe1a82b47
2 changed files with 14 additions and 14 deletions
+7 -10
View File
@@ -8,6 +8,7 @@
// James Garbutt <https://github.com/43081j>
// Bartek Szczepański <https://github.com/barnski>
// Pirasis Leelatanon <https://github.com/1pete>
// Stanislav Dzhus <https://github.com/blablapolicja>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// Imported from: https://github.com/types/npm-redis
@@ -159,8 +160,8 @@ export interface Commands<R> {
/**
* Set multiple hash fields to multiple values.
*/
hmset: OverloadedSetCommand<string | number, boolean, R>;
HMSET: OverloadedSetCommand<string | number, boolean, R>;
hmset: OverloadedSetCommand<string | number, 'OK', R>;
HMSET: OverloadedSetCommand<string | number, 'OK', R>;
/**
* Listen for messages published to the given channels.
@@ -393,8 +394,8 @@ export interface Commands<R> {
/**
* Remove all keys from the current database.
*/
flushdb(cb?: Callback<string>): R;
FLUSHDB(cb?: Callback<string>): R;
flushdb(cb?: Callback<'OK'>): R;
FLUSHDB(cb?: Callback<'OK'>): R;
/**
* Add one or more geospatial items in the geospatial index represented using a sorted set.
@@ -1169,9 +1170,7 @@ export interface Commands<R> {
ZSCAN: OverloadedKeyCommand<string, [string, string[]], R>;
}
export const RedisClient: {
new (options: ClientOpts): RedisClient;
};
export const RedisClient: new (options: ClientOpts) => RedisClient;
export interface RedisClient extends Commands<boolean>, EventEmitter {
connected: boolean;
@@ -1221,9 +1220,7 @@ export interface RedisClient extends Commands<boolean>, EventEmitter {
BATCH(args?: Array<Array<string | number | Callback<any>>>): Multi;
}
export const Multi: {
new (): Multi;
};
export const Multi: new () => Multi;
export interface Multi extends Commands<Multi> {
exec(cb?: Callback<any[]>): boolean;
+7 -4
View File
@@ -9,6 +9,7 @@ const args: any[] = [];
const resCallback: (err: Error | null, res: any) => void = () => {};
const numCallback: (err: Error | null, res: number) => void = () => {};
const strCallback: (err: Error | null, res: string) => void = () => {};
const okCallback: (err: Error | null, res: 'OK') => void = () => {};
const messageHandler: (channel: string, message: any) => void = () => {};
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
@@ -66,7 +67,7 @@ client.unref();
client.append(str, str, numCallback);
client.bitcount(str, numCallback);
client.bitcount(str, num, num, numCallback);
client.set(str, str, strCallback);
client.set(str, str, okCallback);
client.get(str, strCallback);
client.exists(str, numCallback);
@@ -80,15 +81,15 @@ client.once(str, messageHandler);
client.get('test');
client.get('test', resCallback);
client.set('test', 'test');
client.set('test', 'test', resCallback);
client.set('test', 'test', okCallback);
client.mset(args, resCallback);
client.incr(str, resCallback);
// Friendlier hash commands
client.hgetall(str, resCallback);
client.hmset(str, value, resCallback);
client.hmset(str, str, str, str, str, resCallback);
client.hmset(str, value, okCallback);
client.hmset(str, str, str, str, str, okCallback);
// Publish / Subscribe
client.publish(str, value);
@@ -133,3 +134,5 @@ client.hincrbyfloat('a', 'b', 1.5, (error, value) => value.startsWith('1'));
client.HINCRBYFLOAT('a', 'b', 1.5, (error, value) => value.startsWith('1'));
client.zincrby('a', 1, 'b', strCallback);
client.ZINCRBY('a', 1, 'b', strCallback);
client.flushdb(okCallback);