Skip to content

Commit d1d9dba

Browse files
committedMar 14, 2022
fix: rename interfaces by dropping prefix I
1 parent df9330b commit d1d9dba

16 files changed

+117
-136
lines changed
 

‎lib/DataHandler.ts

+29-23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NetStream, CommandItem, ICommand } from "./types";
1+
import { NetStream, CommandItem, Respondable } from "./types";
22
import Deque = require("denque");
33
import { EventEmitter } from "events";
44
import Command from "./command";
@@ -10,35 +10,30 @@ const debug = Debug("dataHandler");
1010

1111
type ReplyData = string | Buffer | number | Array<string | Buffer | number>;
1212

13-
export interface IDataHandlerOptions {
14-
stringNumbers: boolean;
15-
dropBufferSupport: boolean;
16-
}
17-
18-
interface ICondition {
13+
interface Condition {
1914
select: number;
2015
auth: string;
2116
subscriber: false | SubscriptionSet;
2217
}
2318

24-
interface IDataHandledable extends EventEmitter {
19+
interface DataHandledable extends EventEmitter {
2520
stream: NetStream;
2621
status: string;
27-
condition: ICondition;
22+
condition: Condition;
2823
commandQueue: Deque<CommandItem>;
2924

3025
disconnect(reconnect: boolean): void;
3126
recoverFromFatalError(commandError: Error, err: Error, options: any): void;
3227
handleReconnection(err: Error, item: CommandItem): void;
3328
}
3429

35-
interface IParserOptions {
30+
interface ParserOptions {
3631
stringNumbers: boolean;
3732
dropBufferSupport: boolean;
3833
}
3934

4035
export default class DataHandler {
41-
constructor(private redis: IDataHandledable, parserOptions: IParserOptions) {
36+
constructor(private redis: DataHandledable, parserOptions: ParserOptions) {
4237
const parser = new RedisParser({
4338
stringNumbers: parserOptions.stringNumbers,
4439
returnBuffers: !parserOptions.dropBufferSupport,
@@ -230,32 +225,43 @@ export default class DataHandler {
230225
}
231226
}
232227

233-
function fillSubCommand(command: ICommand, count: number) {
234-
// TODO: use WeakMap here
235-
if (typeof (command as any).remainReplies === "undefined") {
236-
(command as any).remainReplies = command.args.length;
237-
}
238-
if (--(command as any).remainReplies === 0) {
228+
const remainingRepliesMap = new WeakMap<Respondable, number>();
229+
230+
function fillSubCommand(command: Respondable, count: number) {
231+
let remainingReplies = remainingRepliesMap.has(command)
232+
? remainingRepliesMap.get(command)
233+
: command.args.length;
234+
235+
remainingReplies -= 1;
236+
237+
if (remainingReplies <= 0) {
239238
command.resolve(count);
239+
remainingRepliesMap.delete(command);
240240
return true;
241241
}
242+
remainingRepliesMap.set(command, remainingReplies);
242243
return false;
243244
}
244245

245-
function fillUnsubCommand(command: ICommand, count: number) {
246-
if (typeof (command as any).remainReplies === "undefined") {
247-
(command as any).remainReplies = command.args.length;
248-
}
249-
if ((command as any).remainReplies === 0) {
246+
function fillUnsubCommand(command: Respondable, count: number) {
247+
let remainingReplies = remainingRepliesMap.has(command)
248+
? remainingRepliesMap.get(command)
249+
: command.args.length;
250+
251+
if (remainingReplies === 0) {
250252
if (count === 0) {
253+
remainingRepliesMap.delete(command);
251254
command.resolve(count);
252255
return true;
253256
}
254257
return false;
255258
}
256-
if (--(command as any).remainReplies === 0) {
259+
260+
remainingReplies -= 1;
261+
if (remainingReplies <= 0) {
257262
command.resolve(count);
258263
return true;
259264
}
265+
remainingRepliesMap.set(command, remainingReplies);
260266
return false;
261267
}

‎lib/ScanStream.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import { Readable, ReadableOptions } from "stream";
2-
/**
3-
* Options for ScanStream
4-
*
5-
* @export
6-
* @interface IScanStreamOptions
7-
* @extends {ReadableOptions}
8-
*/
9-
export interface IScanStreamOptions extends ReadableOptions {
2+
3+
export interface ScanStreamOptions extends ReadableOptions {
104
key?: string;
115
match?: string;
126
type?: string;
@@ -26,7 +20,7 @@ export default class ScanStream extends Readable {
2620
private _redisCursor = "0";
2721
private _redisDrained = false;
2822

29-
constructor(private opt: IScanStreamOptions) {
23+
constructor(private opt: ScanStreamOptions) {
3024
super(opt);
3125
}
3226

‎lib/SubscriptionSet.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { ICommandNameFlags } from "./command";
1+
import { CommandNameFlags } from "./command";
22

3-
type AddSet = ICommandNameFlags["ENTER_SUBSCRIBER_MODE"][number];
4-
type DelSet = ICommandNameFlags["EXIT_SUBSCRIBER_MODE"][number];
3+
type AddSet = CommandNameFlags["ENTER_SUBSCRIBER_MODE"][number];
4+
type DelSet = CommandNameFlags["EXIT_SUBSCRIBER_MODE"][number];
55

66
/**
77
* Tiny class to simplify dealing with subscription set

‎lib/cluster/ClusterOptions.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export type DNSLookupFunction = (
1818
family?: number
1919
) => void
2020
) => void;
21-
export interface INatMap {
21+
export interface NatMap {
2222
[key: string]: { host: string; port: number };
2323
}
2424

@@ -166,7 +166,7 @@ export interface ClusterOptions extends CommanderOptions {
166166
* @default require('dns').lookup
167167
*/
168168
dnsLookup?: DNSLookupFunction;
169-
natMap?: INatMap;
169+
natMap?: NatMap;
170170

171171
/**
172172
* See Redis class.

‎lib/cluster/DelayQueue.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@ import Deque = require("denque");
33

44
const debug = Debug("delayqueue");
55

6-
/**
7-
* Options for DelayQueue
8-
*
9-
* @export
10-
* @interface IDelayQueueOptions
11-
*/
12-
export interface IDelayQueueOptions {
6+
export interface DelayQueueOptions {
137
callback?: Function;
148
timeout: number;
159
}
@@ -29,13 +23,13 @@ export default class DelayQueue {
2923
*
3024
* @param {string} bucket bucket name
3125
* @param {Function} item function that will run later
32-
* @param {IDelayQueueOptions} options
26+
* @param {DelayQueueOptions} options
3327
* @memberof DelayQueue
3428
*/
3529
public push(
3630
bucket: string,
3731
item: Function,
38-
options: IDelayQueueOptions
32+
options: DelayQueueOptions
3933
): void {
4034
const callback = options.callback || process.nextTick;
4135
if (!this.queues[bucket]) {

‎lib/cluster/util.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ export interface RedisOptions {
1313
[key: string]: any;
1414
}
1515

16-
export interface ISrvRecordsGroup {
16+
export interface SrvRecordsGroup {
1717
totalWeight: number;
1818
records: SrvRecord[];
1919
}
2020

21-
export interface IGroupedSrvRecords {
22-
[key: number]: ISrvRecordsGroup;
21+
export interface GroupedSrvRecords {
22+
[key: number]: SrvRecordsGroup;
2323
}
2424

2525
export function getNodeKey(node: RedisOptions): NodeKey {
@@ -80,7 +80,7 @@ export function getUniqueHostnamesFromOptions(nodes: RedisOptions[]): string[] {
8080
return Object.keys(uniqueHostsMap).filter((host) => !isIP(host));
8181
}
8282

83-
export function groupSrvRecords(records: SrvRecord[]): IGroupedSrvRecords {
83+
export function groupSrvRecords(records: SrvRecord[]): GroupedSrvRecords {
8484
const recordsByPriority = {};
8585
for (const record of records) {
8686
if (!recordsByPriority.hasOwnProperty(record.priority)) {
@@ -97,7 +97,7 @@ export function groupSrvRecords(records: SrvRecord[]): IGroupedSrvRecords {
9797
return recordsByPriority;
9898
}
9999

100-
export function weightSrvRecords(recordsGroup: ISrvRecordsGroup): SrvRecord {
100+
export function weightSrvRecords(recordsGroup: SrvRecordsGroup): SrvRecord {
101101
if (recordsGroup.records.length === 1) {
102102
recordsGroup.totalWeight = 0;
103103
return recordsGroup.records.shift();

‎lib/command.ts

+13-16
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,17 @@ import {
88
convertMapToArray,
99
convertObjectToArray,
1010
} from "./utils";
11-
import { CallbackFunction, ICommand, CommandParameter } from "./types";
11+
import { CallbackFunction, Respondable, CommandParameter } from "./types";
1212

1313
export type ArgumentType =
1414
| string
1515
| Buffer
1616
| number
1717
| (string | Buffer | number | any[])[];
1818

19-
interface ICommandOptions {
19+
interface CommandOptions {
2020
/**
2121
* Set the encoding of the reply, by default buffer will be returned.
22-
*
23-
* @type {(string | null)}
24-
* @memberof ICommandOptions
2522
*/
2623
replyEncoding?: BufferEncoding | null;
2724
errorStack?: Error;
@@ -34,11 +31,11 @@ interface ICommandOptions {
3431

3532
type ArgumentTransformer = (args: any[]) => any[];
3633
type ReplyTransformer = (reply: any) => any;
37-
interface IFlagMap {
34+
interface FlagMap {
3835
[flag: string]: { [command: string]: true };
3936
}
4037

41-
export interface ICommandNameFlags {
38+
export interface CommandNameFlags {
4239
// Commands that can be processed when client is in the subscriber mode
4340
VALID_IN_SUBSCRIBER_MODE: [
4441
"subscribe",
@@ -83,9 +80,9 @@ export interface ICommandNameFlags {
8380
* ```
8481
* @see {@link Redis#sendCommand} which can send a Command instance to Redis
8582
*/
86-
export default class Command implements ICommand {
83+
export default class Command implements Respondable {
8784
public static FLAGS: {
88-
[key in keyof ICommandNameFlags]: ICommandNameFlags[key];
85+
[key in keyof CommandNameFlags]: CommandNameFlags[key];
8986
} = {
9087
VALID_IN_SUBSCRIBER_MODE: [
9188
"subscribe",
@@ -101,12 +98,12 @@ export default class Command implements ICommand {
10198
WILL_DISCONNECT: ["quit"],
10299
};
103100

104-
private static flagMap?: IFlagMap;
101+
private static flagMap?: FlagMap;
105102

106-
private static getFlagMap(): IFlagMap {
103+
private static getFlagMap(): FlagMap {
107104
if (!this.flagMap) {
108105
this.flagMap = Object.keys(Command.FLAGS).reduce(
109-
(map: IFlagMap, flagName: string) => {
106+
(map: FlagMap, flagName: string) => {
110107
map[flagName] = {};
111108
Command.FLAGS[flagName].forEach((commandName: string) => {
112109
map[flagName][commandName] = true;
@@ -126,10 +123,10 @@ export default class Command implements ICommand {
126123
* @param {string} commandName
127124
* @return {boolean}
128125
*/
129-
public static checkFlag<T extends keyof ICommandNameFlags>(
126+
public static checkFlag<T extends keyof CommandNameFlags>(
130127
flagName: T,
131128
commandName: string
132-
): commandName is ICommandNameFlags[T][number] {
129+
): commandName is CommandNameFlags[T][number] {
133130
return !!this.getFlagMap()[flagName][commandName];
134131
}
135132

@@ -177,15 +174,15 @@ export default class Command implements ICommand {
177174
* Creates an instance of Command.
178175
* @param {string} name Command name
179176
* @param {(Array<string | Buffer | number>)} [args=[]] An array of command arguments
180-
* @param {ICommandOptions} [options={}]
177+
* @param {CommandOptions} [options={}]
181178
* @param {CallbackFunction} [callback] The callback that handles the response.
182179
* If omit, the response will be handled via Promise
183180
* @memberof Command
184181
*/
185182
constructor(
186183
public name: string,
187184
args: Array<ArgumentType> = [],
188-
options: ICommandOptions = {},
185+
options: CommandOptions = {},
189186
callback?: CallbackFunction
190187
) {
191188
this.replyEncoding = options.replyEncoding;

‎lib/connectors/SentinelConnector/FailoverDetector.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { Debug } from "../../utils";
22
import SentinelConnector from "./index";
3-
import { ISentinel } from "./types";
3+
import { Sentinel } from "./types";
44

55
const debug = Debug("FailoverDetector");
66

77
const CHANNEL_NAME = "+switch-master";
88

99
export class FailoverDetector {
1010
private connector: SentinelConnector;
11-
private sentinels: ISentinel[];
11+
private sentinels: Sentinel[];
1212
private isDisconnected = false;
1313

1414
// sentinels can't be used for regular commands after this
15-
constructor(connector: SentinelConnector, sentinels: ISentinel[]) {
15+
constructor(connector: SentinelConnector, sentinels: Sentinel[]) {
1616
this.connector = connector;
1717
this.sentinels = sentinels;
1818
}

‎lib/connectors/SentinelConnector/SentinelIterator.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { ISentinelAddress } from "./types";
1+
import { SentinelAddress } from "./types";
22

33
function isSentinelEql(
4-
a: Partial<ISentinelAddress>,
5-
b: Partial<ISentinelAddress>
4+
a: Partial<SentinelAddress>,
5+
b: Partial<SentinelAddress>
66
): boolean {
77
return (
88
(a.host || "127.0.0.1") === (b.host || "127.0.0.1") &&
@@ -11,11 +11,12 @@ function isSentinelEql(
1111
}
1212

1313
export default class SentinelIterator
14-
implements Iterator<Partial<ISentinelAddress>> {
14+
implements Iterator<Partial<SentinelAddress>>
15+
{
1516
private cursor = 0;
16-
private sentinels: Array<Partial<ISentinelAddress>>;
17+
private sentinels: Array<Partial<SentinelAddress>>;
1718

18-
constructor(sentinels: Array<Partial<ISentinelAddress>>) {
19+
constructor(sentinels: Array<Partial<SentinelAddress>>) {
1920
this.sentinels = sentinels.slice(0);
2021
}
2122

@@ -35,7 +36,7 @@ export default class SentinelIterator
3536
this.cursor = 0;
3637
}
3738

38-
add(sentinel: ISentinelAddress): boolean {
39+
add(sentinel: SentinelAddress): boolean {
3940
for (let i = 0; i < this.sentinels.length; i++) {
4041
if (isSentinelEql(sentinel, this.sentinels[i])) {
4142
return false;

‎lib/connectors/SentinelConnector/index.ts

+23-25
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { EventEmitter } from "events";
22
import { createConnection, TcpNetConnectOpts } from "net";
3-
import { INatMap } from "../../cluster/ClusterOptions";
3+
import { NatMap } from "../../cluster/ClusterOptions";
44
import {
55
CONNECTION_CLOSED_ERROR_MSG,
66
packObject,
@@ -9,7 +9,7 @@ import {
99
} from "../../utils";
1010
import { connect as createTLSConnection, ConnectionOptions } from "tls";
1111
import SentinelIterator from "./SentinelIterator";
12-
import { IRedisClient, ISentinelAddress, ISentinel } from "./types";
12+
import { RedisClient, SentinelAddress, Sentinel } from "./types";
1313
import AbstractConnector, { ErrorEmitter } from "../AbstractConnector";
1414
import { NetStream } from "../../types";
1515
import Redis from "../../Redis";
@@ -18,26 +18,26 @@ import { FailoverDetector } from "./FailoverDetector";
1818

1919
const debug = Debug("SentinelConnector");
2020

21-
interface IAddressFromResponse {
21+
interface AddressFromResponse {
2222
port: string;
2323
ip: string;
2424
flags?: string;
2525
}
2626

2727
type PreferredSlaves =
28-
| ((slaves: IAddressFromResponse[]) => IAddressFromResponse | null)
28+
| ((slaves: AddressFromResponse[]) => AddressFromResponse | null)
2929
| Array<{ port: string; ip: string; prio?: number }>
3030
| { port: string; ip: string; prio?: number };
3131

32-
export { ISentinelAddress, SentinelIterator };
32+
export { SentinelAddress, SentinelIterator };
3333

3434
export interface SentinelConnectionOptions {
3535
name?: string;
3636
role?: "master" | "slave";
3737
tls?: ConnectionOptions;
3838
sentinelUsername?: string;
3939
sentinelPassword?: string;
40-
sentinels?: Array<Partial<ISentinelAddress>>;
40+
sentinels?: Array<Partial<SentinelAddress>>;
4141
sentinelRetryStrategy?: (retryAttempts: number) => number | void | null;
4242
sentinelReconnectStrategy?: (retryAttempts: number) => number | void | null;
4343
preferredSlaves?: PreferredSlaves;
@@ -46,7 +46,7 @@ export interface SentinelConnectionOptions {
4646
sentinelCommandTimeout?: number;
4747
enableTLSForSentinelMode?: boolean;
4848
sentinelTLS?: ConnectionOptions;
49-
natMap?: INatMap;
49+
natMap?: NatMap;
5050
updateSentinels?: boolean;
5151
sentinelMaxConnections?: number;
5252
failoverDetector?: boolean;
@@ -196,7 +196,7 @@ export default class SentinelConnector extends AbstractConnector {
196196
return connectToNext();
197197
}
198198

199-
private async updateSentinels(client: IRedisClient): Promise<void> {
199+
private async updateSentinels(client: RedisClient): Promise<void> {
200200
if (!this.options.updateSentinels) {
201201
return;
202202
}
@@ -208,8 +208,8 @@ export default class SentinelConnector extends AbstractConnector {
208208
}
209209

210210
result
211-
.map<IAddressFromResponse>(
212-
packObject as (value: any) => IAddressFromResponse
211+
.map<AddressFromResponse>(
212+
packObject as (value: any) => AddressFromResponse
213213
)
214214
.forEach((sentinel) => {
215215
const flags = sentinel.flags ? sentinel.flags.split(",") : [];
@@ -230,7 +230,7 @@ export default class SentinelConnector extends AbstractConnector {
230230
}
231231

232232
private async resolveMaster(
233-
client: IRedisClient
233+
client: RedisClient
234234
): Promise<TcpNetConnectOpts | null> {
235235
const result = await client.sentinel(
236236
"get-master-addr-by-name",
@@ -247,7 +247,7 @@ export default class SentinelConnector extends AbstractConnector {
247247
}
248248

249249
private async resolveSlave(
250-
client: IRedisClient
250+
client: RedisClient
251251
): Promise<TcpNetConnectOpts | null> {
252252
const result = await client.sentinel("slaves", this.options.name);
253253

@@ -256,8 +256,8 @@ export default class SentinelConnector extends AbstractConnector {
256256
}
257257

258258
const availableSlaves = result
259-
.map<IAddressFromResponse>(
260-
packObject as (value: any) => IAddressFromResponse
259+
.map<AddressFromResponse>(
260+
packObject as (value: any) => AddressFromResponse
261261
)
262262
.filter(
263263
(slave) =>
@@ -269,16 +269,16 @@ export default class SentinelConnector extends AbstractConnector {
269269
);
270270
}
271271

272-
sentinelNatResolve(item: ISentinelAddress | null) {
272+
sentinelNatResolve(item: SentinelAddress | null) {
273273
if (!item || !this.options.natMap) return item;
274274

275275
return this.options.natMap[`${item.host}:${item.port}`] || item;
276276
}
277277

278278
private connectToSentinel(
279-
endpoint: Partial<ISentinelAddress>,
279+
endpoint: Partial<SentinelAddress>,
280280
options?: Partial<RedisOptions>
281-
): IRedisClient {
281+
): RedisClient {
282282
const redis = new Redis({
283283
port: endpoint.port || 26379,
284284
host: endpoint.host,
@@ -304,7 +304,7 @@ export default class SentinelConnector extends AbstractConnector {
304304
}
305305

306306
private async resolve(
307-
endpoint: Partial<ISentinelAddress>
307+
endpoint: Partial<SentinelAddress>
308308
): Promise<TcpNetConnectOpts | null> {
309309
const client = this.connectToSentinel(endpoint);
310310

@@ -329,7 +329,7 @@ export default class SentinelConnector extends AbstractConnector {
329329
// Move the current sentinel to the first position
330330
this.sentinelIterator.reset(true);
331331

332-
const sentinels: ISentinel[] = [];
332+
const sentinels: Sentinel[] = [];
333333

334334
// In case of a large amount of sentinels, limit the number of concurrent connections
335335
while (sentinels.length < this.options.sentinelMaxConnections) {
@@ -368,14 +368,14 @@ export default class SentinelConnector extends AbstractConnector {
368368
}
369369

370370
function selectPreferredSentinel(
371-
availableSlaves: IAddressFromResponse[],
371+
availableSlaves: AddressFromResponse[],
372372
preferredSlaves?: PreferredSlaves
373-
): ISentinelAddress | null {
373+
): SentinelAddress | null {
374374
if (availableSlaves.length === 0) {
375375
return null;
376376
}
377377

378-
let selectedSlave: IAddressFromResponse;
378+
let selectedSlave: AddressFromResponse;
379379
if (typeof preferredSlaves === "function") {
380380
selectedSlave = preferredSlaves(availableSlaves);
381381
} else if (preferredSlaves !== null && typeof preferredSlaves === "object") {
@@ -427,9 +427,7 @@ function selectPreferredSentinel(
427427
return addressResponseToAddress(selectedSlave);
428428
}
429429

430-
function addressResponseToAddress(
431-
input: IAddressFromResponse
432-
): ISentinelAddress {
430+
function addressResponseToAddress(input: AddressFromResponse): SentinelAddress {
433431
return { host: input.ip, port: Number(input.port) };
434432
}
435433

‎lib/connectors/SentinelConnector/types.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { RedisOptions } from "../../redis/RedisOptions";
22

3-
export interface ISentinelAddress {
3+
export interface SentinelAddress {
44
port: number;
55
host: string;
66
family?: number;
77
}
88

99
// TODO: A proper typedef. This one only declares a small subset of all the members.
10-
export interface IRedisClient {
10+
export interface RedisClient {
1111
options: RedisOptions;
1212
sentinel(subcommand: "sentinels", name: string): Promise<string[]>;
1313
sentinel(
@@ -25,7 +25,7 @@ export interface IRedisClient {
2525
disconnect(): void;
2626
}
2727

28-
export interface ISentinel {
29-
address: Partial<ISentinelAddress>;
30-
client: IRedisClient;
28+
export interface Sentinel {
29+
address: Partial<SentinelAddress>;
30+
client: RedisClient;
3131
}

‎lib/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export {
1111
} from "./connectors/SentinelConnector";
1212

1313
// Type Exports
14-
export { ISentinelAddress } from "./connectors/SentinelConnector";
14+
export { SentinelAddress } from "./connectors/SentinelConnector";
1515
export { RedisOptions } from "./redis/RedisOptions";
1616

1717
// No TS typings

‎lib/redis/event_handler.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Deque = require("denque");
44
import { AbortError } from "redis-errors";
55
import Command from "../command";
66
import { MaxRetriesPerRequestError } from "../errors";
7-
import { CommandItem, ICommand } from "../types";
7+
import { CommandItem, Respondable } from "../types";
88
import { Debug, noop, CONNECTION_CLOSED_ERROR_MSG } from "../utils";
99
import DataHandler from "../DataHandler";
1010

@@ -100,7 +100,7 @@ export function connectHandler(self) {
100100
};
101101
}
102102

103-
function abortError(command: ICommand) {
103+
function abortError(command: Respondable) {
104104
const err = new AbortError("Command aborted due to connection close");
105105
(err as any).command = {
106106
name: command.name,

‎lib/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type CallbackFunction<T = any> = (
88
export type NetStream = Socket | TLSSocket;
99

1010
export type CommandParameter = string | Buffer | number | any[];
11-
export interface ICommand {
11+
export interface Respondable {
1212
name: string;
1313
args: CommandParameter[];
1414
resolve(result: any): void;
@@ -24,7 +24,7 @@ export interface PipelineWriteableStream {
2424
export type WriteableStream = NetStream | PipelineWriteableStream;
2525

2626
export interface CommandItem {
27-
command: ICommand;
27+
command: Respondable;
2828
stream: WriteableStream;
2929
select: number;
3030
}

‎test/functional/pub_sub.ts

+12-21
Original file line numberDiff line numberDiff line change
@@ -110,27 +110,18 @@ describe("pub/sub", function () {
110110
});
111111
});
112112

113-
it("should exit subscriber mode using punsubscribe", function (done) {
113+
it("should exit subscriber mode using punsubscribe", async () => {
114114
const redis = new Redis();
115-
redis.psubscribe("f?oo", "b?ar", function () {
116-
redis.punsubscribe("f?oo", "b?ar", function (err, count) {
117-
expect(count).to.eql(0);
118-
redis.set("foo", "bar", function (err) {
119-
expect(err).to.eql(null);
115+
await redis.psubscribe("f?oo", "b?ar");
116+
const count = await redis.punsubscribe("f?oo", "b?ar");
117+
expect(count).to.eql(0);
120118

121-
redis.psubscribe("z?oo", "f?oo", function () {
122-
redis.punsubscribe(function (err, count) {
123-
expect(count).to.eql(0);
124-
redis.set("foo", "bar", function (err) {
125-
expect(err).to.eql(null);
126-
redis.disconnect();
127-
done();
128-
});
129-
});
130-
});
131-
});
132-
});
133-
});
119+
await redis.set("foo", "bar");
120+
await redis.psubscribe("z?oo", "f?oo");
121+
const newCount = await redis.punsubscribe();
122+
expect(newCount).to.eql(0);
123+
await redis.set("foo", "bar");
124+
redis.disconnect();
134125
});
135126

136127
it("should be able to send quit command in the subscriber mode", function (done) {
@@ -168,7 +159,7 @@ describe("pub/sub", function () {
168159
pub.publish("bar", "hi2");
169160
});
170161
});
171-
redis.disconnect({ reconnect: true });
162+
redis.disconnect(true);
172163
});
173164
});
174165

@@ -190,7 +181,7 @@ describe("pub/sub", function () {
190181
pub.publish("ba1r", "hi2");
191182
});
192183
});
193-
redis.disconnect({ reconnect: true });
184+
redis.disconnect(true);
194185
});
195186
});
196187
});

‎test/helpers/mock_server.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ export function getConnectionName(socket: Socket): string | undefined {
3232
return connectionNameMap.get(socket);
3333
}
3434

35-
interface IFlags {
35+
interface Flags {
3636
disconnect?: boolean;
3737
hang?: boolean;
3838
}
3939
export type MockServerHandler = (
4040
reply: any,
4141
socket: Socket,
42-
flags: IFlags
42+
flags: Flags
4343
) => any;
4444

4545
export default class MockServer extends EventEmitter {
@@ -92,7 +92,7 @@ export default class MockServer extends EventEmitter {
9292
this.write(c, this.slotTable);
9393
return;
9494
}
95-
const flags: IFlags = {};
95+
const flags: Flags = {};
9696
const handlerResult = this.handler && this.handler(reply, c, flags);
9797
if (!flags.hang) {
9898
this.write(c, handlerResult);

0 commit comments

Comments
 (0)
Please sign in to comment.