mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-21 21:31:12 +08:00
Update redis fix incr return result (#20625)
* Change callback result of incr (increment) variants to be number was string[] * Fix lint errors * Stop using `let` * Remove type annotations for simple string and number constant
This commit is contained in:
91
types/redis/index.d.ts
vendored
91
types/redis/index.d.ts
vendored
@@ -1,6 +1,10 @@
|
||||
// Type definitions for redis 2.6.0
|
||||
// Type definitions for redis 2.8
|
||||
// Project: https://github.com/mranney/node_redis
|
||||
// Definitions by: Carlos Ballesteros Velasco <https://github.com/soywiz>, Peter Harris <https://github.com/CodeAnimal>, TANAKA Koichi <https://github.com/MugeSo>
|
||||
// Definitions by: Carlos Ballesteros Velasco <https://github.com/soywiz>
|
||||
// Peter Harris <https://github.com/CodeAnimal>
|
||||
// TANAKA Koichi <https://github.com/MugeSo>
|
||||
// Stuart Schechter <https://github.com/UppaJung>
|
||||
// Junyoung Choi <https://github.com/Rokt33r>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
// Imported from: https://github.com/types/npm-redis
|
||||
@@ -17,9 +21,7 @@ export interface RetryStrategyOptions {
|
||||
attempt: number;
|
||||
}
|
||||
|
||||
export interface RetryStrategy {
|
||||
(options: RetryStrategyOptions): number | Error;
|
||||
}
|
||||
export type RetryStrategy = (options: RetryStrategyOptions) => number | Error;
|
||||
|
||||
export interface ClientOpts {
|
||||
host?: string;
|
||||
@@ -47,9 +49,7 @@ export interface ClientOpts {
|
||||
retry_strategy?: RetryStrategy;
|
||||
}
|
||||
|
||||
export interface Callback<T> {
|
||||
(err: Error | null, reply: T): void;
|
||||
}
|
||||
export type Callback<T> = (err: Error | null, reply: T) => void;
|
||||
|
||||
export interface ServerInfo {
|
||||
redis_version: string;
|
||||
@@ -57,65 +57,54 @@ export interface ServerInfo {
|
||||
}
|
||||
|
||||
export interface OverloadedCommand<T, U, R> {
|
||||
(args: T[], cb?: Callback<U>): R;
|
||||
(arg: T, args: T[], cb?: Callback<U>): R;
|
||||
|
||||
(arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, arg6: T, cb?: Callback<U>): R;
|
||||
(arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, cb?: Callback<U>): R;
|
||||
(arg1: T, arg2: T, arg3: T, arg4: T, cb?: Callback<U>): R;
|
||||
(arg1: T, arg2: T, arg3: T, cb?: Callback<U>): R;
|
||||
(arg1: T, arg2: T, cb?: Callback<U>): R;
|
||||
(arg1: T, cb?: Callback<U>): R;
|
||||
(...args: (T | Callback<U>)[]): R;
|
||||
(arg1: T, arg2: T | T[], cb?: Callback<U>): R;
|
||||
(arg1: T | T[], cb?: Callback<U>): R;
|
||||
(...args: Array<T | Callback<U>>): R;
|
||||
}
|
||||
|
||||
export interface OverloadedKeyCommand<T, U, R> {
|
||||
(key: string, args: T[], cb?: Callback<U>): R;
|
||||
|
||||
(key: string, arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, arg6: T, cb?: Callback<U>): R;
|
||||
(key: string, arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, cb?: Callback<U>): R;
|
||||
(key: string, arg1: T, arg2: T, arg3: T, arg4: T, cb?: Callback<U>): R;
|
||||
(key: string, arg1: T, arg2: T, arg3: T, cb?: Callback<U>): R;
|
||||
(key: string, arg1: T, arg2: T, cb?: Callback<U>): R;
|
||||
(key: string, arg1: T, cb?: Callback<U>): R;
|
||||
(key: string, ...args: (T | Callback<U>)[]): R;
|
||||
(...args: (string | T | Callback<U>)[]): R;
|
||||
(key: string, arg1: T| T[], cb?: Callback<U>): R;
|
||||
(key: string, ...args: Array<T | Callback<U>>): R;
|
||||
(...args: Array<string | T | Callback<U>>): R;
|
||||
}
|
||||
|
||||
export interface OverloadedListCommand<T, U, R> {
|
||||
(args: T[], cb?: Callback<U>): R;
|
||||
|
||||
(arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, arg6: T, cb?: Callback<U>): R;
|
||||
(arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, cb?: Callback<U>): R;
|
||||
(arg1: T, arg2: T, arg3: T, arg4: T, cb?: Callback<U>): R;
|
||||
(arg1: T, arg2: T, arg3: T, cb?: Callback<U>): R;
|
||||
(arg1: T, arg2: T, cb?: Callback<U>): R;
|
||||
(arg1: T, cb?: Callback<U>): R;
|
||||
(...args: (T | Callback<U>)[]): R;
|
||||
(arg1: T | T[], cb?: Callback<U>): R;
|
||||
(...args: Array<T | Callback<U>>): R;
|
||||
}
|
||||
|
||||
export interface OverloadedSetCommand<T, U, R> {
|
||||
(key: string, args: { [key: string]: T } | T[], cb?: Callback<U>): R;
|
||||
|
||||
(key: string, arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, arg6: T, cb?: Callback<U>): R;
|
||||
(key: string, arg1: T, arg2: T, arg3: T, arg4: T, arg5: T, cb?: Callback<U>): R;
|
||||
(key: string, arg1: T, arg2: T, arg3: T, arg4: T, cb?: Callback<U>): R;
|
||||
(key: string, arg1: T, arg2: T, arg3: T, cb?: Callback<U>): R;
|
||||
(key: string, arg1: T, arg2: T, cb?: Callback<U>): R;
|
||||
(key: string, arg1: T, cb?: Callback<U>): R;
|
||||
(key: string, ...args: (T | Callback<U>)[]): R;
|
||||
(key: string, arg1: T | { [key: string]: T } | T[], cb?: Callback<U>): R;
|
||||
(key: string, ...args: Array<T | Callback<U>>): R;
|
||||
}
|
||||
|
||||
export interface OverloadedLastCommand<T1, T2, U, R> {
|
||||
(args: (T1 | T2)[], cb?: Callback<U>): R;
|
||||
(arg: T1, args: (T1 | T2)[], cb?: Callback<U>): R;
|
||||
|
||||
(arg1: T1, arg2: T1, arg3: T1, arg4: T1, arg5: T1, arg6: T2, cb?: Callback<U>): R;
|
||||
(arg1: T1, arg2: T1, arg3: T1, arg4: T1, arg5: T2, cb?: Callback<U>): R;
|
||||
(arg1: T1, arg2: T1, arg3: T1, arg4: T2, cb?: Callback<U>): R;
|
||||
(arg1: T1, arg2: T1, arg3: T2, cb?: Callback<U>): R;
|
||||
(arg1: T1, arg2: T2, cb?: Callback<U>): R;
|
||||
(...args: (T1 | T2 | Callback<U>)[]): R;
|
||||
(arg1: T1, arg2: T2 | Array<T1 | T2>, cb?: Callback<U>): R;
|
||||
(args: Array<T1 | T2>, cb?: Callback<U>): R;
|
||||
(...args: Array<T1 | T2 | Callback<U>>): R;
|
||||
}
|
||||
|
||||
export interface Commands<R> {
|
||||
@@ -229,11 +218,11 @@ export interface Commands<R> {
|
||||
bitop(operation: string, destkey: string, key1: string, key2: string, key3: string, cb?: Callback<number>): R;
|
||||
bitop(operation: string, destkey: string, key1: string, key2: string, cb?: Callback<number>): R;
|
||||
bitop(operation: string, destkey: string, key: string, cb?: Callback<number>): R;
|
||||
bitop(operation: string, destkey: string, ...args: (string | Callback<number>)[]): R;
|
||||
bitop(operation: string, destkey: string, ...args: Array<string | Callback<number>>): R;
|
||||
BITOP(operation: string, destkey: string, key1: string, key2: string, key3: string, cb?: Callback<number>): R;
|
||||
BITOP(operation: string, destkey: string, key1: string, key2: string, cb?: Callback<number>): R;
|
||||
BITOP(operation: string, destkey: string, key: string, cb?: Callback<number>): R;
|
||||
BITOP(operation: string, destkey: string, ...args: (string | Callback<number>)[]): R;
|
||||
BITOP(operation: string, destkey: string, ...args: Array<string | Callback<number>>): R;
|
||||
|
||||
/**
|
||||
* Find first bit set or clear in a string.
|
||||
@@ -542,20 +531,20 @@ export interface Commands<R> {
|
||||
/**
|
||||
* Increment the integer value of a key by one.
|
||||
*/
|
||||
incr(key: string, cb?: Callback<string[]>): R;
|
||||
INCR(key: string, cb?: Callback<string[]>): R;
|
||||
incr(key: string, cb?: Callback<number>): R;
|
||||
INCR(key: string, cb?: Callback<number>): R;
|
||||
|
||||
/**
|
||||
* Increment the integer value of a key by the given amount.
|
||||
*/
|
||||
incrby(key: string, increment: number, cb?: Callback<string[]>): R;
|
||||
INCRBY(key: string, increment: number, cb?: Callback<string[]>): R;
|
||||
incrby(key: string, increment: number, cb?: Callback<number>): R;
|
||||
INCRBY(key: string, increment: number, cb?: Callback<number>): R;
|
||||
|
||||
/**
|
||||
* Increment the float value of a key by the given amount.
|
||||
*/
|
||||
incrbyfloat(key: string, increment: number, cb?: Callback<string[]>): R;
|
||||
INCRBYFLOAT(key: string, increment: number, cb?: Callback<string[]>): R;
|
||||
incrbyfloat(key: string, increment: number, cb?: Callback<number>): R;
|
||||
INCRBYFLOAT(key: string, increment: number, cb?: Callback<number>): R;
|
||||
|
||||
/**
|
||||
* Find all keys matching the given pattern.
|
||||
@@ -1084,8 +1073,8 @@ export interface Commands<R> {
|
||||
/**
|
||||
* Determine the index of a member in a sorted set.
|
||||
*/
|
||||
zrank(key: string, member: string, cb?: Callback<number | void>): R;
|
||||
ZRANK(key: string, member: string, cb?: Callback<number | void>): R;
|
||||
zrank(key: string, member: string, cb?: Callback<number | undefined>): R;
|
||||
ZRANK(key: string, member: string, cb?: Callback<number | undefined>): R;
|
||||
|
||||
/**
|
||||
* Remove one or more members from a sorted set.
|
||||
@@ -1134,8 +1123,8 @@ export interface Commands<R> {
|
||||
/**
|
||||
* Determine the index of a member in a sorted set, with scores ordered from high to low.
|
||||
*/
|
||||
zrevrank(key: string, member: string, cb?: Callback<number | void>): R;
|
||||
ZREVRANK(key: string, member: string, cb?: Callback<number | void>): R;
|
||||
zrevrank(key: string, member: string, cb?: Callback<number | undefined>): R;
|
||||
ZREVRANK(key: string, member: string, cb?: Callback<number | undefined>): R;
|
||||
|
||||
/**
|
||||
* Get the score associated with the given member in a sorted set.
|
||||
@@ -1190,14 +1179,10 @@ export interface RedisClient extends Commands<boolean>, EventEmitter {
|
||||
server_info: ServerInfo;
|
||||
stream: Duplex;
|
||||
|
||||
on(event: 'message', listener: (channel: string, message: string) => void): this;
|
||||
on(event: 'pmessage', listener: (pattern: string, channel: string, message: string) => void): this;
|
||||
on(event: 'message_buffer', listener: (channel: string, message: string) => void): this;
|
||||
on(event: 'pmessage_buffer', listener: (pattern: string, channel: string, message: string) => void): this;
|
||||
on(event: 'subscribe', listener: (channel: string, count: number) => void): this;
|
||||
on(event: 'psubscribe', listener: (pattern: string, count: number) => void): this;
|
||||
on(event: 'unsubscribe', listener: (channel: string, count: number) => void): this;
|
||||
on(event: 'punsubscribe', listener: (pattern: string, count: number) => void): this;
|
||||
on(event: 'message' | 'message_buffer', listener: (channel: string, message: string) => void): this;
|
||||
on(event: 'pmessage' | 'pmessage_buffer', listener: (pattern: string, channel: string, message: string) => void): this;
|
||||
on(event: 'subscribe' | 'unsubscribe', listener: (channel: string, count: number) => void): this;
|
||||
on(event: 'psubscribe' | 'punsubscribe', listener: (pattern: string, count: number) => void): this;
|
||||
on(event: string, listener: (...args: any[]) => void): this;
|
||||
|
||||
/**
|
||||
@@ -1246,4 +1231,4 @@ export function createClient(unix_socket: string, options?: ClientOpts): RedisCl
|
||||
export function createClient(redis_url: string, options?: ClientOpts): RedisClient;
|
||||
export function createClient(options?: ClientOpts): RedisClient;
|
||||
|
||||
export function print(err: Error | void, reply: any): void;
|
||||
export function print(err: Error | undefined, reply: any): void;
|
||||
|
||||
@@ -1,40 +1,38 @@
|
||||
|
||||
import redis = require('redis');
|
||||
|
||||
var value: any;
|
||||
var valueArr: any[];
|
||||
var commandArr: any[][];
|
||||
var num: number;
|
||||
var str: string;
|
||||
var bool: boolean;
|
||||
var err: Error;
|
||||
var args: any[];
|
||||
var options: redis.ClientOpts;
|
||||
var client: redis.RedisClient;
|
||||
var info: redis.ServerInfo;
|
||||
var resCallback: (err: Error, res: any) => void;
|
||||
var numCallback: (err: Error, res: number) => void;
|
||||
var strCallback: (err: Error, res: string) => void;
|
||||
var messageHandler: (channel: string, message: any) => void;
|
||||
const value: any = 'any value';
|
||||
const commandArr: any[][] = [];
|
||||
const num = 0;
|
||||
const str = 'any string';
|
||||
const err: Error = new Error();
|
||||
const args: any[] = [];
|
||||
const resCallback: (err: Error, res: any) => void = () => null;
|
||||
const numCallback: (err: Error, res: number) => void = () => null;
|
||||
const strCallback: (err: Error, res: string) => void = () => null;
|
||||
const messageHandler: (channel: string, message: any) => void = () => null;
|
||||
|
||||
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
|
||||
|
||||
bool = redis.debug_mode;
|
||||
const debug_mode: boolean = redis.debug_mode;
|
||||
redis.print(err, value);
|
||||
|
||||
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
|
||||
|
||||
client = redis.createClient(num, str, options);
|
||||
const options: redis.ClientOpts = {
|
||||
host: "localhost",
|
||||
port: 6379,
|
||||
};
|
||||
let client: redis.RedisClient = redis.createClient(num, str, options);
|
||||
|
||||
// Test the `retry_strategy` property
|
||||
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
|
||||
function retryStrategyNumber(options: redis.RetryStrategyOptions): number {
|
||||
// Ensure that the properties of RetryStrategyOptions are resilient to breaking change.
|
||||
// If the properties of the interface changes, the variables below will also need to be adapted.
|
||||
var error: Error = options.error;
|
||||
var total_retry_time: number = options.total_retry_time;
|
||||
var times_connected: number = options.times_connected;
|
||||
var attempt: number = options.attempt;
|
||||
const error: Error = options.error;
|
||||
const total_retry_time: number = options.total_retry_time;
|
||||
const times_connected: number = options.times_connected;
|
||||
const attempt: number = options.attempt;
|
||||
return 5000;
|
||||
}
|
||||
function retryStrategyError(options: redis.RetryStrategyOptions): Error {
|
||||
@@ -48,12 +46,12 @@ client = redis.createClient({
|
||||
});
|
||||
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
|
||||
|
||||
bool = client.connected;
|
||||
num = client.retry_delay;
|
||||
num = client.retry_backoff;
|
||||
valueArr = client.command_queue;
|
||||
valueArr = client.offline_queue;
|
||||
info = client.server_info;
|
||||
const connected: boolean = client.connected;
|
||||
const retry_delay: number = client.retry_delay;
|
||||
const retry_backoff: number = client.retry_backoff;
|
||||
const command_queue: any[] = client.command_queue;
|
||||
const offline_queue: any[] = client.offline_queue;
|
||||
const info: redis.ServerInfo = client.server_info;
|
||||
|
||||
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
|
||||
|
||||
|
||||
1
types/redis/tslint.json
Normal file
1
types/redis/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user