ioredis-om 5.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1571 -0
- package/built/Command.d.ts +166 -0
- package/built/Command.js +450 -0
- package/built/DataHandler.d.ts +37 -0
- package/built/DataHandler.js +224 -0
- package/built/Pipeline.d.ts +31 -0
- package/built/Pipeline.js +342 -0
- package/built/Redis.d.ts +243 -0
- package/built/Redis.js +800 -0
- package/built/ScanStream.d.ts +23 -0
- package/built/ScanStream.js +51 -0
- package/built/Script.d.ts +11 -0
- package/built/Script.js +62 -0
- package/built/SubscriptionSet.d.ts +14 -0
- package/built/SubscriptionSet.js +41 -0
- package/built/autoPipelining.d.ts +8 -0
- package/built/autoPipelining.js +167 -0
- package/built/cluster/ClusterOptions.d.ts +172 -0
- package/built/cluster/ClusterOptions.js +22 -0
- package/built/cluster/ClusterSubscriber.d.ts +29 -0
- package/built/cluster/ClusterSubscriber.js +223 -0
- package/built/cluster/ClusterSubscriberGroup.d.ts +108 -0
- package/built/cluster/ClusterSubscriberGroup.js +373 -0
- package/built/cluster/ConnectionPool.d.ts +37 -0
- package/built/cluster/ConnectionPool.js +154 -0
- package/built/cluster/DelayQueue.d.ts +20 -0
- package/built/cluster/DelayQueue.js +53 -0
- package/built/cluster/ShardedSubscriber.d.ts +36 -0
- package/built/cluster/ShardedSubscriber.js +147 -0
- package/built/cluster/index.d.ts +163 -0
- package/built/cluster/index.js +937 -0
- package/built/cluster/util.d.ts +25 -0
- package/built/cluster/util.js +100 -0
- package/built/connectors/AbstractConnector.d.ts +12 -0
- package/built/connectors/AbstractConnector.js +26 -0
- package/built/connectors/ConnectorConstructor.d.ts +5 -0
- package/built/connectors/ConnectorConstructor.js +2 -0
- package/built/connectors/SentinelConnector/FailoverDetector.d.ts +11 -0
- package/built/connectors/SentinelConnector/FailoverDetector.js +45 -0
- package/built/connectors/SentinelConnector/SentinelIterator.d.ts +13 -0
- package/built/connectors/SentinelConnector/SentinelIterator.js +37 -0
- package/built/connectors/SentinelConnector/index.d.ts +72 -0
- package/built/connectors/SentinelConnector/index.js +305 -0
- package/built/connectors/SentinelConnector/types.d.ts +21 -0
- package/built/connectors/SentinelConnector/types.js +2 -0
- package/built/connectors/StandaloneConnector.d.ts +17 -0
- package/built/connectors/StandaloneConnector.js +69 -0
- package/built/connectors/index.d.ts +3 -0
- package/built/connectors/index.js +7 -0
- package/built/constants/TLSProfiles.d.ts +9 -0
- package/built/constants/TLSProfiles.js +149 -0
- package/built/errors/ClusterAllFailedError.d.ts +7 -0
- package/built/errors/ClusterAllFailedError.js +15 -0
- package/built/errors/MaxRetriesPerRequestError.d.ts +5 -0
- package/built/errors/MaxRetriesPerRequestError.js +14 -0
- package/built/errors/index.d.ts +2 -0
- package/built/errors/index.js +5 -0
- package/built/index.d.ts +44 -0
- package/built/index.js +62 -0
- package/built/redis/RedisOptions.d.ts +197 -0
- package/built/redis/RedisOptions.js +58 -0
- package/built/redis/event_handler.d.ts +4 -0
- package/built/redis/event_handler.js +315 -0
- package/built/tracing.d.ts +26 -0
- package/built/tracing.js +96 -0
- package/built/transaction.d.ts +13 -0
- package/built/transaction.js +100 -0
- package/built/types.d.ts +33 -0
- package/built/types.js +2 -0
- package/built/utils/Commander.d.ts +50 -0
- package/built/utils/Commander.js +117 -0
- package/built/utils/RedisCommander.d.ts +8950 -0
- package/built/utils/RedisCommander.js +7 -0
- package/built/utils/applyMixin.d.ts +3 -0
- package/built/utils/applyMixin.js +8 -0
- package/built/utils/argumentParsers.d.ts +14 -0
- package/built/utils/argumentParsers.js +74 -0
- package/built/utils/debug.d.ts +16 -0
- package/built/utils/debug.js +95 -0
- package/built/utils/index.d.ts +124 -0
- package/built/utils/index.js +332 -0
- package/built/utils/lodash.d.ts +4 -0
- package/built/utils/lodash.js +9 -0
- package/package.json +103 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const util_1 = require("./util");
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const Redis_1 = require("../Redis");
|
|
6
|
+
const debug = (0, utils_1.Debug)("cluster:subscriberGroup:shardedSubscriber");
|
|
7
|
+
const SubscriberStatus = {
|
|
8
|
+
IDLE: "idle",
|
|
9
|
+
STARTING: "starting",
|
|
10
|
+
CONNECTED: "connected",
|
|
11
|
+
STOPPING: "stopping",
|
|
12
|
+
ENDED: "ended",
|
|
13
|
+
};
|
|
14
|
+
const ALLOWED_STATUS_UPDATES = {
|
|
15
|
+
[SubscriberStatus.IDLE]: [
|
|
16
|
+
SubscriberStatus.STARTING,
|
|
17
|
+
SubscriberStatus.STOPPING,
|
|
18
|
+
SubscriberStatus.ENDED,
|
|
19
|
+
],
|
|
20
|
+
[SubscriberStatus.STARTING]: [
|
|
21
|
+
SubscriberStatus.CONNECTED,
|
|
22
|
+
SubscriberStatus.STOPPING,
|
|
23
|
+
SubscriberStatus.ENDED,
|
|
24
|
+
],
|
|
25
|
+
[SubscriberStatus.CONNECTED]: [
|
|
26
|
+
SubscriberStatus.STOPPING,
|
|
27
|
+
SubscriberStatus.ENDED,
|
|
28
|
+
],
|
|
29
|
+
[SubscriberStatus.STOPPING]: [SubscriberStatus.ENDED],
|
|
30
|
+
[SubscriberStatus.ENDED]: [],
|
|
31
|
+
};
|
|
32
|
+
class ShardedSubscriber {
|
|
33
|
+
constructor(emitter, options, redisOptions) {
|
|
34
|
+
var _a;
|
|
35
|
+
this.emitter = emitter;
|
|
36
|
+
this.status = SubscriberStatus.IDLE;
|
|
37
|
+
this.instance = null;
|
|
38
|
+
this.connectPromise = null;
|
|
39
|
+
// Store listener references for cleanup
|
|
40
|
+
this.messageListeners = new Map();
|
|
41
|
+
this.onEnd = () => {
|
|
42
|
+
this.updateStatus(SubscriberStatus.ENDED);
|
|
43
|
+
this.emitter.emit("-node", this.instance, this.nodeKey);
|
|
44
|
+
};
|
|
45
|
+
this.onError = (error) => {
|
|
46
|
+
this.emitter.emit("nodeError", error, this.nodeKey);
|
|
47
|
+
};
|
|
48
|
+
this.onMoved = () => {
|
|
49
|
+
this.emitter.emit("moved");
|
|
50
|
+
};
|
|
51
|
+
this.instance = new Redis_1.default((0, utils_1.defaults)({
|
|
52
|
+
enableReadyCheck: false,
|
|
53
|
+
enableOfflineQueue: true,
|
|
54
|
+
connectionName: (0, util_1.getConnectionName)("ssubscriber", options.connectionName),
|
|
55
|
+
/**
|
|
56
|
+
* Disable auto reconnection for subscribers.
|
|
57
|
+
* The ClusterSubscriberGroup will handle the reconnection.
|
|
58
|
+
*/
|
|
59
|
+
retryStrategy: null,
|
|
60
|
+
lazyConnect: true,
|
|
61
|
+
}, options, redisOptions));
|
|
62
|
+
this.lazyConnect = (_a = redisOptions === null || redisOptions === void 0 ? void 0 : redisOptions.lazyConnect) !== null && _a !== void 0 ? _a : true;
|
|
63
|
+
this.nodeKey = (0, util_1.getNodeKey)(options);
|
|
64
|
+
// Register listeners
|
|
65
|
+
this.instance.on("end", this.onEnd);
|
|
66
|
+
this.instance.on("error", this.onError);
|
|
67
|
+
this.instance.on("moved", this.onMoved);
|
|
68
|
+
for (const event of ["smessage", "smessageBuffer"]) {
|
|
69
|
+
const listener = (...args) => {
|
|
70
|
+
this.emitter.emit(event, ...args);
|
|
71
|
+
};
|
|
72
|
+
this.messageListeners.set(event, listener);
|
|
73
|
+
this.instance.on(event, listener);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async start() {
|
|
77
|
+
if (this.connectPromise) {
|
|
78
|
+
return this.connectPromise;
|
|
79
|
+
}
|
|
80
|
+
if (this.status === SubscriberStatus.STARTING ||
|
|
81
|
+
this.status === SubscriberStatus.CONNECTED) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (this.status === SubscriberStatus.ENDED || !this.instance) {
|
|
85
|
+
throw new Error(`Sharded subscriber ${this.nodeKey} cannot be restarted once ended.`);
|
|
86
|
+
}
|
|
87
|
+
this.updateStatus(SubscriberStatus.STARTING);
|
|
88
|
+
this.connectPromise = this.instance.connect();
|
|
89
|
+
try {
|
|
90
|
+
await this.connectPromise;
|
|
91
|
+
this.updateStatus(SubscriberStatus.CONNECTED);
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
this.updateStatus(SubscriberStatus.ENDED);
|
|
95
|
+
throw err;
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
this.connectPromise = null;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
stop() {
|
|
102
|
+
this.updateStatus(SubscriberStatus.STOPPING);
|
|
103
|
+
if (this.instance) {
|
|
104
|
+
this.instance.disconnect();
|
|
105
|
+
this.instance.removeAllListeners();
|
|
106
|
+
this.messageListeners.clear();
|
|
107
|
+
this.instance = null;
|
|
108
|
+
}
|
|
109
|
+
this.updateStatus(SubscriberStatus.ENDED);
|
|
110
|
+
debug("stopped %s", this.nodeKey);
|
|
111
|
+
}
|
|
112
|
+
isStarted() {
|
|
113
|
+
return [
|
|
114
|
+
SubscriberStatus.CONNECTED,
|
|
115
|
+
SubscriberStatus.STARTING,
|
|
116
|
+
].includes(this.status);
|
|
117
|
+
}
|
|
118
|
+
get subscriberStatus() {
|
|
119
|
+
return this.status;
|
|
120
|
+
}
|
|
121
|
+
isHealthy() {
|
|
122
|
+
return ((this.status === SubscriberStatus.IDLE ||
|
|
123
|
+
this.status === SubscriberStatus.CONNECTED ||
|
|
124
|
+
this.status === SubscriberStatus.STARTING) &&
|
|
125
|
+
this.instance !== null);
|
|
126
|
+
}
|
|
127
|
+
getInstance() {
|
|
128
|
+
return this.instance;
|
|
129
|
+
}
|
|
130
|
+
getNodeKey() {
|
|
131
|
+
return this.nodeKey;
|
|
132
|
+
}
|
|
133
|
+
isLazyConnect() {
|
|
134
|
+
return this.lazyConnect;
|
|
135
|
+
}
|
|
136
|
+
updateStatus(nextStatus) {
|
|
137
|
+
if (this.status === nextStatus) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (!ALLOWED_STATUS_UPDATES[this.status].includes(nextStatus)) {
|
|
141
|
+
debug("Invalid status transition for %s: %s -> %s", this.nodeKey, this.status, nextStatus);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
this.status = nextStatus;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.default = ShardedSubscriber;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from "events";
|
|
3
|
+
import Command from "../Command";
|
|
4
|
+
import Redis from "../Redis";
|
|
5
|
+
import ScanStream from "../ScanStream";
|
|
6
|
+
import { Transaction } from "../transaction";
|
|
7
|
+
import { Callback, ScanStreamOptions, WriteableStream } from "../types";
|
|
8
|
+
import Commander from "../utils/Commander";
|
|
9
|
+
import { ClusterOptions } from "./ClusterOptions";
|
|
10
|
+
import { NodeKey, NodeRole } from "./util";
|
|
11
|
+
export declare type ClusterNode = string | number | {
|
|
12
|
+
host?: string | undefined;
|
|
13
|
+
port?: number | undefined;
|
|
14
|
+
};
|
|
15
|
+
declare type ClusterStatus = "end" | "close" | "wait" | "connecting" | "connect" | "ready" | "reconnecting" | "disconnecting";
|
|
16
|
+
/**
|
|
17
|
+
* Client for the official Redis Cluster
|
|
18
|
+
*/
|
|
19
|
+
declare class Cluster extends Commander {
|
|
20
|
+
options: ClusterOptions;
|
|
21
|
+
slots: NodeKey[][];
|
|
22
|
+
status: ClusterStatus;
|
|
23
|
+
/**
|
|
24
|
+
* @ignore
|
|
25
|
+
*/
|
|
26
|
+
_groupsIds: {
|
|
27
|
+
[key: string]: number;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* @ignore
|
|
31
|
+
*/
|
|
32
|
+
_groupsBySlot: number[];
|
|
33
|
+
/**
|
|
34
|
+
* @ignore
|
|
35
|
+
*/
|
|
36
|
+
isCluster: boolean;
|
|
37
|
+
private startupNodes;
|
|
38
|
+
private connectionPool;
|
|
39
|
+
private manuallyClosing;
|
|
40
|
+
private retryAttempts;
|
|
41
|
+
private delayQueue;
|
|
42
|
+
private offlineQueue;
|
|
43
|
+
private subscriber;
|
|
44
|
+
private shardedSubscribers;
|
|
45
|
+
private slotsTimer;
|
|
46
|
+
private reconnectTimeout;
|
|
47
|
+
private isRefreshing;
|
|
48
|
+
private _refreshSlotsCacheCallbacks;
|
|
49
|
+
private _autoPipelines;
|
|
50
|
+
private _runningAutoPipelines;
|
|
51
|
+
private _readyDelayedCallbacks;
|
|
52
|
+
private subscriberGroupEmitter;
|
|
53
|
+
/**
|
|
54
|
+
* Every time Cluster#connect() is called, this value will be
|
|
55
|
+
* auto-incrementing. The purpose of this value is used for
|
|
56
|
+
* discarding previous connect attampts when creating a new
|
|
57
|
+
* connection.
|
|
58
|
+
*/
|
|
59
|
+
private connectionEpoch;
|
|
60
|
+
/**
|
|
61
|
+
* Creates an instance of Cluster.
|
|
62
|
+
*/
|
|
63
|
+
constructor(startupNodes: ClusterNode[], options?: ClusterOptions);
|
|
64
|
+
/**
|
|
65
|
+
* Connect to a cluster
|
|
66
|
+
*/
|
|
67
|
+
connect(): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Disconnect from every node in the cluster.
|
|
70
|
+
*/
|
|
71
|
+
disconnect(reconnect?: boolean): void;
|
|
72
|
+
/**
|
|
73
|
+
* Quit the cluster gracefully.
|
|
74
|
+
*/
|
|
75
|
+
quit(callback?: Callback<"OK">): Promise<"OK">;
|
|
76
|
+
/**
|
|
77
|
+
* Create a new instance with the same startup nodes and options as the current one.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```js
|
|
81
|
+
* var cluster = new Redis.Cluster([{ host: "127.0.0.1", port: "30001" }]);
|
|
82
|
+
* var anotherCluster = cluster.duplicate();
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
duplicate(overrideStartupNodes?: any[], overrideOptions?: {}): Cluster;
|
|
86
|
+
/**
|
|
87
|
+
* Get nodes with the specified role
|
|
88
|
+
*/
|
|
89
|
+
nodes(role?: NodeRole): Redis[];
|
|
90
|
+
/**
|
|
91
|
+
* This is needed in order not to install a listener for each auto pipeline
|
|
92
|
+
*
|
|
93
|
+
* @ignore
|
|
94
|
+
*/
|
|
95
|
+
delayUntilReady(callback: Callback): void;
|
|
96
|
+
/**
|
|
97
|
+
* Get the number of commands queued in automatic pipelines.
|
|
98
|
+
*
|
|
99
|
+
* This is not available (and returns 0) until the cluster is connected and slots information have been received.
|
|
100
|
+
*/
|
|
101
|
+
get autoPipelineQueueSize(): number;
|
|
102
|
+
/**
|
|
103
|
+
* Refresh the slot cache
|
|
104
|
+
*
|
|
105
|
+
* @ignore
|
|
106
|
+
*/
|
|
107
|
+
refreshSlotsCache(callback?: Callback<void>): void;
|
|
108
|
+
/**
|
|
109
|
+
* @ignore
|
|
110
|
+
*/
|
|
111
|
+
sendCommand(command: Command, stream?: WriteableStream, node?: any): unknown;
|
|
112
|
+
sscanStream(key: string, options?: ScanStreamOptions): ScanStream;
|
|
113
|
+
sscanBufferStream(key: string, options?: ScanStreamOptions): ScanStream;
|
|
114
|
+
hscanStream(key: string, options?: ScanStreamOptions): ScanStream;
|
|
115
|
+
hscanBufferStream(key: string, options?: ScanStreamOptions): ScanStream;
|
|
116
|
+
zscanStream(key: string, options?: ScanStreamOptions): ScanStream;
|
|
117
|
+
zscanBufferStream(key: string, options?: ScanStreamOptions): ScanStream;
|
|
118
|
+
/**
|
|
119
|
+
* @ignore
|
|
120
|
+
*/
|
|
121
|
+
handleError(error: Error, ttl: {
|
|
122
|
+
value?: any;
|
|
123
|
+
}, handlers: any): void;
|
|
124
|
+
private resetOfflineQueue;
|
|
125
|
+
private clearNodesRefreshInterval;
|
|
126
|
+
private resetNodesRefreshInterval;
|
|
127
|
+
/**
|
|
128
|
+
* Change cluster instance's status
|
|
129
|
+
*/
|
|
130
|
+
private setStatus;
|
|
131
|
+
/**
|
|
132
|
+
* Called when closed to check whether a reconnection should be made
|
|
133
|
+
*/
|
|
134
|
+
private handleCloseEvent;
|
|
135
|
+
/**
|
|
136
|
+
* Flush offline queue with error.
|
|
137
|
+
*/
|
|
138
|
+
private flushQueue;
|
|
139
|
+
private executeOfflineCommands;
|
|
140
|
+
private natMapper;
|
|
141
|
+
private getInfoFromNode;
|
|
142
|
+
private invokeReadyDelayedCallbacks;
|
|
143
|
+
/**
|
|
144
|
+
* Check whether Cluster is able to process commands
|
|
145
|
+
*/
|
|
146
|
+
private readyCheck;
|
|
147
|
+
private resolveSrv;
|
|
148
|
+
private dnsLookup;
|
|
149
|
+
/**
|
|
150
|
+
* Normalize startup nodes, and resolving hostnames to IPs.
|
|
151
|
+
*
|
|
152
|
+
* This process happens every time when #connect() is called since
|
|
153
|
+
* #startupNodes and DNS records may chanage.
|
|
154
|
+
*/
|
|
155
|
+
private resolveStartupNodeHostnames;
|
|
156
|
+
private createScanStream;
|
|
157
|
+
private createShardedSubscriberGroup;
|
|
158
|
+
}
|
|
159
|
+
interface Cluster extends EventEmitter {
|
|
160
|
+
}
|
|
161
|
+
interface Cluster extends Transaction {
|
|
162
|
+
}
|
|
163
|
+
export default Cluster;
|