Skip to content

Commit 06782e6

Browse files
committedMar 14, 2022
feat: improve typings for cluster
1 parent 756e1a7 commit 06782e6

24 files changed

+10310
-1511
lines changed
 

‎bin/generateRedisCommander/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ async function main() {
3232
"latency",
3333
"lolwut",
3434
"memory",
35+
"cluster",
3536
],
3637
});
3738

‎bin/generateRedisCommander/returnTypes.js

+45
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,51 @@ module.exports = {
3131
return "string";
3232
}
3333
},
34+
cluster: (types) => {
35+
if (matchSubcommand(types, "SLOTS")) {
36+
return "[startSlotRange: number, endSlotRange: number, ...nodes: [host: string, port: number, nodeId: string, info: unknown[]][]][]";
37+
}
38+
if (
39+
matchSubcommand(types, [
40+
"ADDSLOTS",
41+
"ADDSLOTSRANGE",
42+
"DELSLOTS",
43+
"DELSLOTSRANGE",
44+
"FAILOVER",
45+
"FLUSHSLOTS",
46+
"FORGET",
47+
"MEET",
48+
"REPLICATE",
49+
"RESET",
50+
"SAVECONFIG",
51+
"SET-CONFIG-EPOCH",
52+
"SETSLOT",
53+
])
54+
) {
55+
return "'OK'";
56+
}
57+
if (matchSubcommand(types, "BUMPEPOCH")) {
58+
return "'BUMPED' | 'STILL'";
59+
}
60+
if (
61+
matchSubcommand(types, [
62+
"COUNT-FAILURE-REPORTS",
63+
"COUNTKEYSINSLOT",
64+
"KEYSLOT",
65+
])
66+
) {
67+
return "number";
68+
}
69+
if (matchSubcommand(types, "GETKEYSINSLOT")) {
70+
return "string[]";
71+
}
72+
if (matchSubcommand(types, ["INFO", "MYID"])) {
73+
return "string";
74+
}
75+
if (matchSubcommand(types, "LINKS")) {
76+
return "unknown[]";
77+
}
78+
},
3479
append: "number",
3580
asking: "'OK'",
3681
auth: "'OK'",

‎lib/Redis.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,14 @@ class Redis extends Commander {
125125
this.resetCommandQueue();
126126
this.resetOfflineQueue();
127127

128-
if ("Connector" in this.options && this.options.Connector) {
128+
if (this.options.Connector) {
129129
this.connector = new this.options.Connector(this.options);
130-
} else if ("sentinels" in this.options && this.options.sentinels) {
130+
} else if (this.options.sentinels) {
131131
const sentinelConnector = new SentinelConnector(this.options);
132132
sentinelConnector.emitter = this;
133133

134134
this.connector = sentinelConnector;
135135
} else {
136-
// @ts-expect-error
137136
this.connector = new StandaloneConnector(this.options);
138137
}
139138

‎lib/cluster/ConnectionPool.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type NODE_TYPE = "all" | "master" | "slave";
99

1010
export default class ConnectionPool extends EventEmitter {
1111
// master + slave = all
12-
private nodes: { [key in NODE_TYPE]: { [key: string]: any } } = {
12+
private nodes: { [key in NODE_TYPE]: { [key: string]: Redis } } = {
1313
all: {},
1414
master: {},
1515
slave: {},
@@ -21,16 +21,16 @@ export default class ConnectionPool extends EventEmitter {
2121
super();
2222
}
2323

24-
getNodes(role: NodeRole = "all"): any[] {
24+
getNodes(role: NodeRole = "all"): Redis[] {
2525
const nodes = this.nodes[role];
2626
return Object.keys(nodes).map((key) => nodes[key]);
2727
}
2828

29-
getInstanceByKey(key: NodeKey): any {
29+
getInstanceByKey(key: NodeKey): Redis {
3030
return this.nodes.all[key];
3131
}
3232

33-
getSampleInstance(role: NodeRole): any {
33+
getSampleInstance(role: NodeRole): Redis {
3434
const keys = Object.keys(this.nodes[role]);
3535
const sampleKey = sample(keys);
3636
return this.nodes[role][sampleKey];
@@ -39,7 +39,7 @@ export default class ConnectionPool extends EventEmitter {
3939
/**
4040
* Find or create a connection to the node
4141
*/
42-
findOrCreate(node: RedisOptions, readOnly = false): any {
42+
findOrCreate(node: RedisOptions, readOnly = false): Redis {
4343
const key = getNodeKey(node);
4444
readOnly = Boolean(readOnly);
4545

@@ -49,7 +49,7 @@ export default class ConnectionPool extends EventEmitter {
4949
this.specifiedOptions[key] = node;
5050
}
5151

52-
let redis;
52+
let redis: Redis;
5353
if (this.nodes.all[key]) {
5454
redis = this.nodes.all[key];
5555
if (redis.options.readOnly !== readOnly) {

‎lib/cluster/index.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ class Cluster extends Commander {
346346
/**
347347
* Get nodes with the specified role
348348
*/
349-
nodes(role: NodeRole = "all"): any[] {
349+
nodes(role: NodeRole = "all"): Redis[] {
350350
if (role !== "all" && role !== "master" && role !== "slave") {
351351
throw new Error(
352352
'Invalid role "' + role + '". Expected "all", "master" or "slave"'
@@ -696,7 +696,6 @@ class Cluster extends Commander {
696696
nextRound();
697697
}
698698

699-
700699
/**
701700
* Change cluster instance's status
702701
*/
@@ -785,7 +784,7 @@ class Cluster extends Commander {
785784
: nodeKey;
786785
}
787786

788-
private getInfoFromNode(redis, callback) {
787+
private getInfoFromNode(redis: Redis, callback) {
789788
if (!redis) {
790789
return callback(new Error("Node is disconnected"));
791790
}
@@ -808,7 +807,7 @@ class Cluster extends Commander {
808807
duplicatedConnection.on("error", noop);
809808

810809
duplicatedConnection.cluster(
811-
"slots",
810+
"SLOTS",
812811
timeout((err, result) => {
813812
duplicatedConnection.disconnect();
814813
if (err) {
@@ -827,7 +826,7 @@ class Cluster extends Commander {
827826
callback();
828827
return;
829828
}
830-
const nodes = [];
829+
const nodes: RedisOptions[] = [];
831830

832831
debug("cluster slots result count: %d", result.length);
833832

@@ -841,10 +840,13 @@ class Cluster extends Commander {
841840
if (!items[j][0]) {
842841
continue;
843842
}
844-
items[j] = this.natMapper({ host: items[j][0], port: items[j][1] });
845-
items[j].readOnly = j !== 2;
846-
nodes.push(items[j]);
847-
keys.push(items[j].host + ":" + items[j].port);
843+
const node = this.natMapper({
844+
host: items[j][0],
845+
port: items[j][1],
846+
});
847+
node.readOnly = j !== 2;
848+
nodes.push(node);
849+
keys.push(node.host + ":" + node.port);
848850
}
849851

850852
debug(
@@ -896,7 +898,7 @@ class Cluster extends Commander {
896898
* Check whether Cluster is able to process commands
897899
*/
898900
private readyCheck(callback: Callback<void | "fail">): void {
899-
(this as any).cluster("info", function (err, res) {
901+
this.cluster("INFO", function (err, res) {
900902
if (err) {
901903
return callback(err);
902904
}

‎lib/connectors/StandaloneConnector.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import { createConnection, TcpNetConnectOpts, IpcNetConnectOpts } from "net";
1+
import { createConnection, IpcNetConnectOpts, TcpNetConnectOpts } from "net";
22
import { connect as createTLSConnection, ConnectionOptions } from "tls";
3+
import { NetStream } from "../types";
34
import { CONNECTION_CLOSED_ERROR_MSG } from "../utils";
45
import AbstractConnector, { ErrorEmitter } from "./AbstractConnector";
5-
import { NetStream } from "../types";
66

7-
export type StandaloneConnectionOptions = (
8-
| TcpNetConnectOpts
9-
| IpcNetConnectOpts
10-
) & { disconnectTimeout: number; tls?: ConnectionOptions };
7+
export type StandaloneConnectionOptions = (Partial<TcpNetConnectOpts> &
8+
Partial<IpcNetConnectOpts>) & {
9+
disconnectTimeout?: number;
10+
tls?: ConnectionOptions;
11+
};
1112

1213
export default class StandaloneConnector extends AbstractConnector {
1314
constructor(protected options: StandaloneConnectionOptions) {

‎lib/constants/TLSProfiles.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default {
1+
const TLSProfiles = {
22
/**
33
* TLS settings for Redis.com Cloud Fixed plan. Updated on 2021-10-06.
44
*/
@@ -100,4 +100,6 @@ export default {
100100
"UhWfa/HQYOAPDdEjNgnVwLI23b8t0TozyCWw7q8h\n" +
101101
"-----END CERTIFICATE-----\n",
102102
},
103-
};
103+
} as const;
104+
105+
export default TLSProfiles;

‎lib/redis/RedisOptions.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ interface CommonRedisOptions extends CommanderOptions {
3535
lazyConnect?: boolean;
3636
}
3737

38-
export type RedisOptions =
39-
| (CommonRedisOptions & SentinelConnectionOptions)
40-
| (CommonRedisOptions & StandaloneConnectionOptions);
38+
export type RedisOptions = CommonRedisOptions &
39+
SentinelConnectionOptions &
40+
StandaloneConnectionOptions;
4141

4242
export const DEFAULT_REDIS_OPTIONS: RedisOptions = {
4343
// Connection

‎lib/utils/RedisCommander.ts

+10,119-1,413
Large diffs are not rendered by default.

‎lib/utils/index.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,18 @@ export function packObject(array: any[]): Record<string, any> {
106106
/**
107107
* Return a callback with timeout
108108
*/
109-
export function timeout(callback: Callback, timeout: number) {
110-
let timer: NodeJS.Timeout;
111-
const run = function () {
109+
export function timeout<T>(
110+
callback: Callback<T>,
111+
timeout: number
112+
): Callback<T> {
113+
let timer: ReturnType<typeof setTimeout> | null = null;
114+
const run: Callback<T> = function () {
112115
if (timer) {
113116
clearTimeout(timer);
114117
timer = null;
115118
callback.apply(this, arguments);
116119
}
117120
};
118-
// @ts-expect-error we are using `arguments`
119121
timer = setTimeout(run, timeout, new Error("timeout"));
120122
return run;
121123
}

‎test-d/options.test-d.ts

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { expectType } from "tsd";
2+
import Redis, { Cluster } from "../built";
3+
4+
expectType<Redis>(new Redis());
5+
6+
// TCP
7+
expectType<Redis>(new Redis());
8+
expectType<Redis>(new Redis(6379));
9+
expectType<Redis>(new Redis({ port: 6379 }));
10+
expectType<Redis>(new Redis({ host: "localhost" }));
11+
expectType<Redis>(new Redis({ host: "localhost", port: 6379 }));
12+
expectType<Redis>(new Redis({ host: "localhost", port: 6379, family: 4 }));
13+
expectType<Redis>(new Redis({ host: "localhost", port: 6379, family: 4 }));
14+
expectType<Redis>(new Redis(6379, "localhost", { password: "password" }));
15+
16+
// Socket
17+
expectType<Redis>(new Redis("/tmp/redis.sock"));
18+
expectType<Redis>(new Redis("/tmp/redis.sock", { password: "password" }));
19+
20+
// TLS
21+
expectType<Redis>(new Redis({ tls: {} }));
22+
expectType<Redis>(new Redis({ tls: { ca: "myca" } }));
23+
24+
// Sentinels
25+
expectType<Redis>(
26+
new Redis({
27+
sentinels: [{ host: "localhost", port: 16379 }],
28+
sentinelPassword: "password",
29+
})
30+
);
31+
32+
// Cluster
33+
expectType<Cluster>(new Cluster([30001, 30002]));
34+
expectType<Cluster>(new Redis.Cluster([30001, 30002]));
35+
expectType<Cluster>(new Redis.Cluster([30001, "localhost"]));
36+
expectType<Cluster>(new Redis.Cluster([30001, "localhost", { port: 30002 }]));
37+
expectType<Cluster>(
38+
new Redis.Cluster([30001, 30002], {
39+
enableAutoPipelining: true,
40+
})
41+
);

‎test/functional/cluster/ask.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe("cluster:ASK", () => {
1212
[2, 16383, ["127.0.0.1", 30002]],
1313
];
1414
new MockServer(30001, (argv) => {
15-
if (argv[0] === "cluster" && argv[1] === "slots") {
15+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
1616
return slotTable;
1717
}
1818
if (argv[0] === "get" && argv[1] === "foo") {
@@ -22,7 +22,7 @@ describe("cluster:ASK", () => {
2222
}
2323
});
2424
new MockServer(30002, (argv) => {
25-
if (argv[0] === "cluster" && argv[1] === "slots") {
25+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
2626
return slotTable;
2727
}
2828
if (argv[0] === "get" && argv[1] === "foo") {
@@ -57,7 +57,7 @@ describe("cluster:ASK", () => {
5757
}
5858
});
5959
new MockServer(30002, (argv) => {
60-
if (argv[0] === "cluster" && argv[1] === "slots") {
60+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
6161
return slotTable;
6262
}
6363
if (argv[0] === "get" && argv[1] === "foo") {

‎test/functional/cluster/autopipelining.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe("autoPipelining for cluster", () => {
2424
];
2525

2626
new MockServer(30001, (argv) => {
27-
if (argv[0] === "cluster" && argv[1] === "slots") {
27+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
2828
return slotTable;
2929
}
3030

@@ -42,7 +42,7 @@ describe("autoPipelining for cluster", () => {
4242
});
4343

4444
new MockServer(30002, (argv) => {
45-
if (argv[0] === "cluster" && argv[1] === "slots") {
45+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
4646
return slotTable;
4747
}
4848

@@ -56,7 +56,7 @@ describe("autoPipelining for cluster", () => {
5656
});
5757

5858
new MockServer(30003, (argv) => {
59-
if (argv[0] === "cluster" && argv[1] === "slots") {
59+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
6060
return slotTable;
6161
}
6262

‎test/functional/cluster/clusterdown.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ describe("cluster:CLUSTERDOWN", () => {
99
[2, 16383, ["127.0.0.1", 30002]],
1010
];
1111
new MockServer(30001, (argv) => {
12-
if (argv[0] === "cluster" && argv[1] === "slots") {
12+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
1313
return slotTable;
1414
}
1515
if (argv[0] === "get" && argv[1] === "foo") {
1616
return "bar";
1717
}
1818
});
1919
new MockServer(30002, (argv) => {
20-
if (argv[0] === "cluster" && argv[1] === "slots") {
20+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
2121
return slotTable;
2222
}
2323
if (argv[0] === "get" && argv[1] === "foo") {

‎test/functional/cluster/connect.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ describe("cluster:connect", () => {
8888
if (argv[0] === "info") {
8989
// return 'role:master'
9090
}
91-
if (argv[0] === "cluster" && argv[1] === "slots") {
91+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
9292
return slotTable;
9393
}
94-
if (argv[0] === "cluster" && argv[1] === "info") {
94+
if (argv[0] === "cluster" && argv[1] === "INFO") {
9595
return "cluster_state:ok";
9696
}
9797
};
@@ -137,7 +137,7 @@ describe("cluster:connect", () => {
137137
[10923, 16383, ["127.0.0.1", 30003]],
138138
];
139139
const argvHandler = function (argv) {
140-
if (argv[0] === "cluster" && argv[1] === "slots") {
140+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
141141
return slotTable;
142142
}
143143
};
@@ -196,7 +196,7 @@ describe("cluster:connect", () => {
196196
[10923, 16383, ["127.0.0.1", 30003]],
197197
];
198198
const argvHandler = function (argv) {
199-
if (argv[0] === "cluster" && argv[1] === "slots") {
199+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
200200
return slotTable;
201201
}
202202
};
@@ -223,7 +223,7 @@ describe("cluster:connect", () => {
223223

224224
it("should send command to the correct node", (done) => {
225225
new MockServer(30001, (argv) => {
226-
if (argv[0] === "cluster" && argv[1] === "slots") {
226+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
227227
return [
228228
[0, 1, ["127.0.0.1", 30001]],
229229
[2, 16383, ["127.0.0.1", 30002]],
@@ -248,7 +248,7 @@ describe("cluster:connect", () => {
248248
it("should emit errors when cluster cannot be connected", (done) => {
249249
const errorMessage = "ERR This instance has cluster support disabled";
250250
const argvHandler = function (argv) {
251-
if (argv[0] === "cluster" && argv[1] === "slots") {
251+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
252252
return new Error(errorMessage);
253253
}
254254
};
@@ -297,7 +297,7 @@ describe("cluster:connect", () => {
297297
[10923, 16383, ["127.0.0.1", 30003]],
298298
];
299299
const argvHandler = function (port, argv) {
300-
if (argv[0] === "cluster" && argv[1] === "slots") {
300+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
301301
return slotTable;
302302
}
303303
if (argv[0] === "auth") {
@@ -330,7 +330,7 @@ describe("cluster:connect", () => {
330330
let times = 0;
331331
let cluster;
332332
const argvHandler = function (argv) {
333-
if (argv[0] === "cluster" && argv[1] === "slots") {
333+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
334334
times++;
335335
if (times === 1) {
336336
return [

‎test/functional/cluster/index.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe("cluster", () => {
88
it("should return the error successfully", (done) => {
99
let called = false;
1010
new MockServer(30001, (argv) => {
11-
if (argv[0] === "cluster" && argv[1] === "slots") {
11+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
1212
return [[0, 16383, ["127.0.0.1", 30001]]];
1313
}
1414
if (argv.toString() === "get,foo,bar") {
@@ -28,7 +28,7 @@ describe("cluster", () => {
2828

2929
it("should get value successfully", (done) => {
3030
new MockServer(30001, (argv) => {
31-
if (argv[0] === "cluster" && argv[1] === "slots") {
31+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
3232
return [
3333
[0, 1, ["127.0.0.1", 30001]],
3434
[2, 16383, ["127.0.0.1", 30002]],
@@ -53,9 +53,9 @@ describe("cluster", () => {
5353
it("should reconnect when cluster state is not ok", (done) => {
5454
let state = "fail";
5555
new MockServer(30001, (argv) => {
56-
if (argv[0] === "cluster" && argv[1] === "slots") {
56+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
5757
return [[0, 16383, ["127.0.0.1", 30001]]];
58-
} else if (argv[0] === "cluster" && argv[1] === "info") {
58+
} else if (argv[0] === "cluster" && argv[1] === "INFO") {
5959
return "cluster_state:" + state;
6060
}
6161
});
@@ -87,10 +87,10 @@ describe("cluster", () => {
8787
describe("startupNodes", () => {
8888
it("should allow updating startupNodes", (done) => {
8989
new MockServer(30001, (argv) => {
90-
if (argv[0] === "cluster" && argv[1] === "slots") {
90+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
9191
return [[0, 16383, ["127.0.0.1", 30001]]];
9292
}
93-
if (argv[0] === "cluster" && argv[1] === "info") {
93+
if (argv[0] === "cluster" && argv[1] === "INFO") {
9494
return "cluster_state:fail";
9595
}
9696
});
@@ -123,7 +123,7 @@ describe("cluster", () => {
123123
describe("scaleReads", () => {
124124
beforeEach(function () {
125125
function handler(port, argv) {
126-
if (argv[0] === "cluster" && argv[1] === "slots") {
126+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
127127
return [
128128
[
129129
0,
@@ -305,18 +305,18 @@ describe("cluster", () => {
305305
[16382, 16383, ["127.0.0.1", 30002]],
306306
];
307307
const node = new MockServer(30001, (argv) => {
308-
if (argv[0] === "cluster" && argv[1] === "slots") {
308+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
309309
return slotTable;
310310
}
311311
});
312312
new MockServer(30002, (argv) => {
313-
if (argv[0] === "cluster" && argv[1] === "slots") {
313+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
314314
return slotTable;
315315
}
316316
});
317317

318318
new MockServer(30003, (argv) => {
319-
if (argv[0] === "cluster" && argv[1] === "slots") {
319+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
320320
return slotTable;
321321
}
322322
});
@@ -349,18 +349,18 @@ describe("cluster", () => {
349349
[5461, 10922, ["127.0.0.1", 30002]],
350350
];
351351
new MockServer(30001, (argv) => {
352-
if (argv[0] === "cluster" && argv[1] === "slots") {
352+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
353353
return slotTable;
354354
}
355355
});
356356
new MockServer(30002, (argv) => {
357-
if (argv[0] === "cluster" && argv[1] === "slots") {
357+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
358358
return slotTable;
359359
}
360360
});
361361

362362
new MockServer(30003, (argv) => {
363-
if (argv[0] === "cluster" && argv[1] === "slots") {
363+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
364364
return slotTable;
365365
}
366366
});
@@ -402,7 +402,7 @@ describe("cluster", () => {
402402
[2, 16383, ["127.0.0.1", 30002], ["127.0.0.1", 30003]],
403403
];
404404
const argvHandler = function (argv) {
405-
if (argv[0] === "cluster" && argv[1] === "slots") {
405+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
406406
return slotTable;
407407
}
408408
};

‎test/functional/cluster/maxRedirections.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe("cluster:maxRedirections", () => {
77
it("should return error when reached max redirection", (done) => {
88
let redirectTimes = 0;
99
const argvHandler = function (argv) {
10-
if (argv[0] === "cluster" && argv[1] === "slots") {
10+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
1111
return [
1212
[0, 1, ["127.0.0.1", 30001]],
1313
[2, 16383, ["127.0.0.1", 30002]],

‎test/functional/cluster/moved.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe("cluster:MOVED", () => {
1414
[2, 16383, ["127.0.0.1", 30002]],
1515
];
1616
new MockServer(30001, (argv) => {
17-
if (argv[0] === "cluster" && argv[1] === "slots") {
17+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
1818
return slotTable;
1919
}
2020
if (argv[0] === "get" && argv[1] === "foo") {
@@ -28,7 +28,7 @@ describe("cluster:MOVED", () => {
2828
}
2929
});
3030
new MockServer(30002, (argv) => {
31-
if (argv[0] === "cluster" && argv[1] === "slots") {
31+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
3232
return slotTable;
3333
}
3434
if (argv[0] === "get" && argv[1] === "foo") {
@@ -48,15 +48,15 @@ describe("cluster:MOVED", () => {
4848

4949
it("should be able to redirect a command to a unknown node", (done) => {
5050
new MockServer(30001, (argv) => {
51-
if (argv[0] === "cluster" && argv[1] === "slots") {
51+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
5252
return [[0, 16383, ["127.0.0.1", 30001]]];
5353
}
5454
if (argv[0] === "get" && argv[1] === "foo") {
5555
return new Error("MOVED " + calculateSlot("foo") + " 127.0.0.1:30002");
5656
}
5757
});
5858
new MockServer(30002, (argv) => {
59-
if (argv[0] === "cluster" && argv[1] === "slots") {
59+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
6060
return [
6161
[0, 16381, ["127.0.0.1", 30001]],
6262
[16382, 16383, ["127.0.0.1", 30002]],
@@ -85,7 +85,7 @@ describe("cluster:MOVED", () => {
8585
[2, 16383, ["127.0.0.1", 30002]],
8686
];
8787
new MockServer(30001, (argv) => {
88-
if (argv[0] === "cluster" && argv[1] === "slots") {
88+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
8989
return slotTable;
9090
}
9191
if (argv[0] === "get" && argv[1] === "foo") {
@@ -99,7 +99,7 @@ describe("cluster:MOVED", () => {
9999
}
100100
});
101101
new MockServer(30002, (argv) => {
102-
if (argv[0] === "cluster" && argv[1] === "slots") {
102+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
103103
return slotTable;
104104
}
105105
if (argv[0] === "get" && argv[1] === "foo") {
@@ -123,7 +123,7 @@ describe("cluster:MOVED", () => {
123123
let cluster = undefined;
124124
const slotTable = [[0, 16383, ["127.0.0.1", 30001]]];
125125
new MockServer(30001, (argv) => {
126-
if (argv[0] === "cluster" && argv[1] === "slots") {
126+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
127127
return slotTable;
128128
}
129129
if (argv[0] === "get" && argv[1] === "foo") {
@@ -132,7 +132,7 @@ describe("cluster:MOVED", () => {
132132
});
133133

134134
new MockServer(30002, (argv) => {
135-
if (argv[0] === "cluster" && argv[1] === "slots") {
135+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
136136
return slotTable;
137137
}
138138
if (argv[0] === "get" && argv[1] === "foo") {

‎test/functional/cluster/pipeline.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ describe("cluster:pipeline", () => {
1111
[12182, 16383, ["127.0.0.1", 30002]],
1212
];
1313
new MockServer(30001, (argv) => {
14-
if (argv[0] === "cluster" && argv[1] === "slots") {
14+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
1515
return slotTable;
1616
}
1717
});
1818
new MockServer(30002, (argv) => {
19-
if (argv[0] === "cluster" && argv[1] === "slots") {
19+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
2020
return slotTable;
2121
}
2222
});
@@ -42,12 +42,12 @@ describe("cluster:pipeline", () => {
4242
[12182, 16383, ["127.0.0.1", 30002]],
4343
];
4444
new MockServer(30001, (argv) => {
45-
if (argv[0] === "cluster" && argv[1] === "slots") {
45+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
4646
return slotTable;
4747
}
4848
});
4949
new MockServer(30002, (argv) => {
50-
if (argv[0] === "cluster" && argv[1] === "slots") {
50+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
5151
return slotTable;
5252
}
5353
});
@@ -74,15 +74,15 @@ describe("cluster:pipeline", () => {
7474
[12182, 16383, ["127.0.0.1", 30002]],
7575
];
7676
new MockServer(30001, (argv) => {
77-
if (argv[0] === "cluster" && argv[1] === "slots") {
77+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
7878
return slotTable;
7979
}
8080
if (argv[0] === "get" && argv[1] === "foo") {
8181
return "bar";
8282
}
8383
});
8484
new MockServer(30002, (argv) => {
85-
if (argv[0] === "cluster" && argv[1] === "slots") {
85+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
8686
return slotTable;
8787
}
8888
if (argv[1] === "foo") {
@@ -115,7 +115,7 @@ describe("cluster:pipeline", () => {
115115
[12182, 16383, ["127.0.0.1", 30002]],
116116
];
117117
new MockServer(30001, (argv) => {
118-
if (argv[0] === "cluster" && argv[1] === "slots") {
118+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
119119
return slotTable;
120120
}
121121
if (argv[0] === "asking") {
@@ -130,7 +130,7 @@ describe("cluster:pipeline", () => {
130130
}
131131
});
132132
new MockServer(30002, (argv) => {
133-
if (argv[0] === "cluster" && argv[1] === "slots") {
133+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
134134
return slotTable;
135135
}
136136
if (argv[1] === "foo") {
@@ -156,7 +156,7 @@ describe("cluster:pipeline", () => {
156156
let times = 0;
157157
const slotTable = [[0, 16383, ["127.0.0.1", 30001]]];
158158
new MockServer(30001, (argv) => {
159-
if (argv[0] === "cluster" && argv[1] === "slots") {
159+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
160160
return slotTable;
161161
}
162162
if (argv[1] === "foo") {
@@ -189,15 +189,15 @@ describe("cluster:pipeline", () => {
189189
[12182, 16383, ["127.0.0.1", 30002]],
190190
];
191191
new MockServer(30001, (argv) => {
192-
if (argv[0] === "cluster" && argv[1] === "slots") {
192+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
193193
return slotTable;
194194
}
195195
if (argv[0] === "get" && argv[1] === "foo") {
196196
return "bar";
197197
}
198198
});
199199
new MockServer(30002, (argv) => {
200-
if (argv[0] === "cluster" && argv[1] === "slots") {
200+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
201201
return slotTable;
202202
}
203203
if (argv[0] === "get" && argv[1] === "foo") {
@@ -225,12 +225,12 @@ describe("cluster:pipeline", () => {
225225
[12182, 16383, ["127.0.0.1", 30002]],
226226
];
227227
new MockServer(30001, (argv) => {
228-
if (argv[0] === "cluster" && argv[1] === "slots") {
228+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
229229
return slotTable;
230230
}
231231
});
232232
const node2 = new MockServer(30002, (argv) => {
233-
if (argv[0] === "cluster" && argv[1] === "slots") {
233+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
234234
return slotTable;
235235
}
236236
if (argv[0] === "get" && argv[1] === "foo") {

‎test/functional/cluster/pub_sub.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { noop } from "../../../lib/utils";
88
describe("cluster:pub/sub", function () {
99
it("should receive messages", (done) => {
1010
const handler = function (argv) {
11-
if (argv[0] === "cluster" && argv[1] === "slots") {
11+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
1212
return [
1313
[0, 1, ["127.0.0.1", 30001]],
1414
[2, 16383, ["127.0.0.1", 30002]],
@@ -38,7 +38,7 @@ describe("cluster:pub/sub", function () {
3838

3939
it("should works when sending regular commands", (done) => {
4040
const handler = function (argv) {
41-
if (argv[0] === "cluster" && argv[1] === "slots") {
41+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
4242
return [[0, 16383, ["127.0.0.1", 30001]]];
4343
}
4444
};
@@ -64,7 +64,7 @@ describe("cluster:pub/sub", function () {
6464
expect(c.password).to.eql("abc");
6565
expect(getConnectionName(c)).to.eql("ioredis-cluster(subscriber)");
6666
}
67-
if (argv[0] === "cluster" && argv[1] === "slots") {
67+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
6868
return [[0, 16383, ["127.0.0.1", 30001]]];
6969
}
7070
};
@@ -79,7 +79,7 @@ describe("cluster:pub/sub", function () {
7979

8080
it("should re-subscribe after reconnection", (done) => {
8181
new MockServer(30001, function (argv) {
82-
if (argv[0] === "cluster" && argv[1] === "slots") {
82+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
8383
return [[0, 16383, ["127.0.0.1", 30001]]];
8484
} else if (argv[0] === "subscribe" || argv[0] === "psubscribe") {
8585
return [argv[0], argv[1]];
@@ -106,7 +106,7 @@ describe("cluster:pub/sub", function () {
106106

107107
it("should re-psubscribe after reconnection", (done) => {
108108
new MockServer(30001, function (argv) {
109-
if (argv[0] === "cluster" && argv[1] === "slots") {
109+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
110110
return [[0, 16383, ["127.0.0.1", 30001]]];
111111
} else if (argv[0] === "subscribe" || argv[0] === "psubscribe") {
112112
return [argv[0], argv[1]];

‎test/functional/cluster/tls.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe("cluster:tls option", () => {
1313
[10923, 16383, ["127.0.0.1", 30003]],
1414
];
1515
const argvHandler = function (argv) {
16-
if (argv[0] === "cluster" && argv[1] === "slots") {
16+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
1717
return slotTable;
1818
}
1919
};

‎test/functional/cluster/transaction.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe("cluster:transaction", () => {
1111
[12182, 16383, ["127.0.0.1", 30002]],
1212
];
1313
new MockServer(30001, (argv) => {
14-
if (argv[0] === "cluster" && argv[1] === "slots") {
14+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
1515
return slotTable;
1616
}
1717
if (argv[1] === "foo") {
@@ -23,7 +23,7 @@ describe("cluster:transaction", () => {
2323
}
2424
});
2525
new MockServer(30002, (argv) => {
26-
if (argv[0] === "cluster" && argv[1] === "slots") {
26+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
2727
return slotTable;
2828
}
2929
if (argv[0] === "get" && argv[1] === "foo") {
@@ -59,7 +59,7 @@ describe("cluster:transaction", () => {
5959
[12182, 16383, ["127.0.0.1", 30002]],
6060
];
6161
new MockServer(30001, (argv) => {
62-
if (argv[0] === "cluster" && argv[1] === "slots") {
62+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
6363
return slotTable;
6464
}
6565
if (argv[0] === "asking") {
@@ -81,7 +81,7 @@ describe("cluster:transaction", () => {
8181
}
8282
});
8383
new MockServer(30002, (argv) => {
84-
if (argv[0] === "cluster" && argv[1] === "slots") {
84+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
8585
return slotTable;
8686
}
8787
if (argv[0] === "get" && argv[1] === "foo") {

‎test/functional/cluster/tryagain.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe("cluster:TRYAGAIN", () => {
77
let times = 0;
88
const slotTable = [[0, 16383, ["127.0.0.1", 30001]]];
99
new MockServer(30001, (argv) => {
10-
if (argv[0] === "cluster" && argv[1] === "slots") {
10+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
1111
return slotTable;
1212
}
1313
if (argv[0] === "get" && argv[1] === "foo") {

‎test/functional/scan_stream.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ describe("*scanStream", () => {
175175
];
176176
const serverKeys = ["foo1", "foo2", "foo3", "foo4", "foo10"];
177177
const argvHandler = function (argv) {
178-
if (argv[0] === "cluster" && argv[1] === "slots") {
178+
if (argv[0] === "cluster" && argv[1] === "SLOTS") {
179179
return slotTable;
180180
}
181181
if (argv[0] === "sscan" && argv[1] === "set") {

0 commit comments

Comments
 (0)
Please sign in to comment.