@iobroker/db-base 4.0.21 → 4.1.0-alpha.0-20220819-74ceeddc
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/build/index.d.ts +4 -0
- package/build/index.js +10 -0
- package/build/lib/constants.d.ts +4 -0
- package/build/lib/constants.d.ts.map +1 -0
- package/build/lib/constants.js +11 -0
- package/build/lib/constants.js.map +1 -0
- package/build/lib/inMemFileDB.d.ts +130 -0
- package/build/lib/inMemFileDB.d.ts.map +1 -0
- package/{lib → build/lib}/inMemFileDB.js +119 -207
- package/build/lib/inMemFileDB.js.map +1 -0
- package/build/lib/redisHandler.d.ts +165 -0
- package/build/lib/redisHandler.d.ts.map +1 -0
- package/{lib → build/lib}/redisHandler.js +93 -145
- package/build/lib/redisHandler.js.map +1 -0
- package/package.json +24 -8
- package/index.js +0 -5
- package/lib/constants.js +0 -6
- package/lib/tools.js +0 -21
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.RedisHandler = void 0;
|
|
7
|
+
// @ts-expect-error no types
|
|
8
|
+
const respjs_1 = __importDefault(require("respjs"));
|
|
9
|
+
const events_1 = require("events");
|
|
10
|
+
const constants_1 = require("./constants");
|
|
5
11
|
/**
|
|
6
12
|
* Class to handle a redis connection and provide events to react on for
|
|
7
13
|
* all incoming Redis commands
|
|
8
14
|
*/
|
|
9
|
-
class RedisHandler extends EventEmitter {
|
|
15
|
+
class RedisHandler extends events_1.EventEmitter {
|
|
10
16
|
/**
|
|
11
17
|
* Initialize and register all data handlers to send out events on new commands
|
|
12
18
|
* @param socket Network Socket/Connection
|
|
@@ -14,7 +20,6 @@ class RedisHandler extends EventEmitter {
|
|
|
14
20
|
*/
|
|
15
21
|
constructor(socket, options) {
|
|
16
22
|
super();
|
|
17
|
-
|
|
18
23
|
options = options || {};
|
|
19
24
|
this.options = options;
|
|
20
25
|
this.log = options.log || console;
|
|
@@ -23,59 +28,48 @@ class RedisHandler extends EventEmitter {
|
|
|
23
28
|
this.logScope += ' ';
|
|
24
29
|
}
|
|
25
30
|
this.socket = socket;
|
|
26
|
-
|
|
27
31
|
this.socketId = `${this.logScope + socket.remoteAddress}:${socket.remotePort}`;
|
|
28
32
|
this.initialized = false;
|
|
29
33
|
this.stop = false;
|
|
30
|
-
|
|
31
34
|
this.activeMultiCalls = [];
|
|
32
35
|
this.writeQueue = [];
|
|
33
|
-
|
|
34
36
|
this.handleBuffers = false;
|
|
35
37
|
const respOptions = {};
|
|
36
38
|
if (options.handleAsBuffers) {
|
|
37
39
|
this.handleBuffers = true;
|
|
38
40
|
respOptions.bufBulk = true;
|
|
39
41
|
}
|
|
40
|
-
this.resp = new
|
|
41
|
-
|
|
42
|
-
this.resp.on('error', err => {
|
|
42
|
+
this.resp = new respjs_1.default(respOptions);
|
|
43
|
+
this.resp.on('error', (err) => {
|
|
43
44
|
this.log.error(`${this.socketId} (Init=${this.initialized}) Redis error:${err}`);
|
|
44
45
|
if (this.initialized) {
|
|
45
46
|
this.sendError(null, new Error(`PARSER ERROR ${err}`)); // TODO
|
|
46
|
-
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
47
49
|
this.close();
|
|
48
50
|
}
|
|
49
51
|
});
|
|
50
|
-
|
|
51
|
-
this.resp.on('data', data => this._handleCommand(data));
|
|
52
|
-
|
|
52
|
+
this.resp.on('data', (data) => this._handleCommand(data));
|
|
53
53
|
socket.on('data', data => {
|
|
54
54
|
if (this.options.enhancedLogging) {
|
|
55
|
-
this.log.silly(
|
|
56
|
-
`${
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
.substring(0, 100)} -- ${data.length} bytes`
|
|
62
|
-
: data.toString().replace(/[\r\n]+/g, '')
|
|
63
|
-
}`
|
|
64
|
-
);
|
|
55
|
+
this.log.silly(`${this.socketId} New Redis request: ${data.length > 1024
|
|
56
|
+
? `${data
|
|
57
|
+
.toString()
|
|
58
|
+
.replace(/[\r\n]+/g, '')
|
|
59
|
+
.substring(0, 100)} -- ${data.length} bytes`
|
|
60
|
+
: data.toString().replace(/[\r\n]+/g, '')}`);
|
|
65
61
|
}
|
|
66
62
|
this.resp.write(data);
|
|
67
63
|
});
|
|
68
|
-
|
|
69
64
|
socket.on('error', err => {
|
|
70
65
|
if (!this.stop) {
|
|
71
|
-
this.log.debug(`${this.socketId} Redis Socket error: ${err}`);
|
|
66
|
+
this.log.debug(`${this.socketId} Redis Socket error: ${err.stack}`);
|
|
72
67
|
}
|
|
73
68
|
if (this.socket) {
|
|
74
69
|
this.socket.destroy();
|
|
75
70
|
}
|
|
76
71
|
});
|
|
77
72
|
}
|
|
78
|
-
|
|
79
73
|
/**
|
|
80
74
|
* Handle one incoming command, assign responseId and emit event to be handled
|
|
81
75
|
* @param data Array RESP data
|
|
@@ -98,20 +92,13 @@ class RedisHandler extends EventEmitter {
|
|
|
98
92
|
}
|
|
99
93
|
}
|
|
100
94
|
}
|
|
101
|
-
|
|
102
95
|
const t = process.hrtime();
|
|
103
96
|
const responseId = t[0] * 1e3 + t[1] / 1e6;
|
|
104
|
-
|
|
105
97
|
if (this.options.enhancedLogging) {
|
|
106
|
-
this.log.silly(
|
|
107
|
-
`${
|
|
108
|
-
|
|
109
|
-
? `${JSON.stringify(data).substring(0, 100)} -- ${JSON.stringify(data).length} bytes`
|
|
110
|
-
: JSON.stringify(data)
|
|
111
|
-
}`
|
|
112
|
-
);
|
|
98
|
+
this.log.silly(`${this.socketId} Parser result: id=${responseId}, command=${command}, data=${JSON.stringify(data).length > 1024
|
|
99
|
+
? `${JSON.stringify(data).substring(0, 100)} -- ${JSON.stringify(data).length} bytes`
|
|
100
|
+
: JSON.stringify(data)}`);
|
|
113
101
|
}
|
|
114
|
-
|
|
115
102
|
if (command === 'multi') {
|
|
116
103
|
if (this.activeMultiCalls.length && !this.activeMultiCalls[0].execCalled) {
|
|
117
104
|
// should never happen
|
|
@@ -120,34 +107,31 @@ class RedisHandler extends EventEmitter {
|
|
|
120
107
|
this._handleMulti();
|
|
121
108
|
return;
|
|
122
109
|
}
|
|
123
|
-
|
|
124
110
|
// multi active and exec not called yet
|
|
125
111
|
if (this.activeMultiCalls.length && !this.activeMultiCalls[0].execCalled && command !== 'exec') {
|
|
126
112
|
// store all response ids so we know which need to be in the multi call
|
|
127
113
|
this.activeMultiCalls[0].responseIds.push(responseId);
|
|
128
114
|
// add it for the correct order will be overwritten with correct response
|
|
129
115
|
this.activeMultiCalls[0].responseMap.set(responseId, null);
|
|
130
|
-
}
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
131
118
|
// multi response ids should not be pushed - we will answer combined
|
|
132
119
|
this.writeQueue.push({ id: responseId, data: false });
|
|
133
120
|
}
|
|
134
|
-
|
|
135
121
|
if (command === 'exec') {
|
|
136
122
|
this._handleExec(responseId);
|
|
137
123
|
return;
|
|
138
124
|
}
|
|
139
|
-
|
|
140
125
|
if (command === 'info') {
|
|
141
126
|
this.initialized = true;
|
|
142
127
|
}
|
|
143
|
-
|
|
144
128
|
if (this.listenerCount(command) !== 0) {
|
|
145
129
|
setImmediate(() => this.emit(command, data, responseId));
|
|
146
|
-
}
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
147
132
|
this.sendError(responseId, new Error(`${command} NOT SUPPORTED`));
|
|
148
133
|
}
|
|
149
134
|
}
|
|
150
|
-
|
|
151
135
|
/**
|
|
152
136
|
* Check if the response to a certain command can be send out directly or
|
|
153
137
|
* if it needs to wait till earlier responses are ready
|
|
@@ -157,7 +141,6 @@ class RedisHandler extends EventEmitter {
|
|
|
157
141
|
*/
|
|
158
142
|
_sendQueued(responseId, data) {
|
|
159
143
|
let idx = 0;
|
|
160
|
-
|
|
161
144
|
while (this.writeQueue.length && idx < this.writeQueue.length) {
|
|
162
145
|
// we found the queue entry that matches with the responseId, so store the data so be sent out
|
|
163
146
|
if (this.writeQueue[idx].id === responseId) {
|
|
@@ -173,34 +156,28 @@ class RedisHandler extends EventEmitter {
|
|
|
173
156
|
if (idx === 0 && this.writeQueue[idx].data !== false) {
|
|
174
157
|
const response = this.writeQueue.shift();
|
|
175
158
|
if (this.options.enhancedLogging) {
|
|
176
|
-
this.log.silly(
|
|
177
|
-
`${
|
|
178
|
-
|
|
179
|
-
? `${data.length} bytes`
|
|
180
|
-
: response.data.toString().replace(/[\r\n]+/g, '')
|
|
181
|
-
}`
|
|
182
|
-
);
|
|
159
|
+
this.log.silly(`${this.socketId} Redis response (${response.id}): ${response.data.length > 1024
|
|
160
|
+
? `${data.length} bytes`
|
|
161
|
+
: response.data.toString().replace(/[\r\n]+/g, '')}`);
|
|
183
162
|
}
|
|
184
|
-
|
|
185
163
|
this._write(response.data);
|
|
186
164
|
// We sended out first queue entry but no further response is ready
|
|
187
165
|
// and we do not need to check the whole queue, so we are done here
|
|
188
166
|
if (this.writeQueue.length && this.writeQueue[idx].data === false) {
|
|
189
167
|
break;
|
|
190
168
|
}
|
|
191
|
-
}
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
192
171
|
// we have not found the response on the current index, try next one
|
|
193
172
|
idx++;
|
|
194
173
|
}
|
|
195
174
|
}
|
|
196
|
-
|
|
197
175
|
if (idx > 0) {
|
|
198
176
|
if (this.options.enhancedLogging) {
|
|
199
177
|
this.log.silly(`${this.socketId} Redis response (${responseId}): Response queued`);
|
|
200
178
|
}
|
|
201
179
|
}
|
|
202
180
|
}
|
|
203
|
-
|
|
204
181
|
/**
|
|
205
182
|
* Really write out a response to the network connection
|
|
206
183
|
* @param data Buffer to send out
|
|
@@ -209,7 +186,6 @@ class RedisHandler extends EventEmitter {
|
|
|
209
186
|
_write(data) {
|
|
210
187
|
this.socket.write(data);
|
|
211
188
|
}
|
|
212
|
-
|
|
213
189
|
/**
|
|
214
190
|
* Guard to make sure a response is valid to be sent out
|
|
215
191
|
* @param responseId ID of the response
|
|
@@ -228,12 +204,10 @@ class RedisHandler extends EventEmitter {
|
|
|
228
204
|
}
|
|
229
205
|
if (!data) {
|
|
230
206
|
this.log.warn(`${this.socketId} Not able to write ${JSON.stringify(data)}`);
|
|
231
|
-
data =
|
|
207
|
+
data = respjs_1.default.encodeError(new Error(`INVALID RESPONSE: ${JSON.stringify(data)}`));
|
|
232
208
|
}
|
|
233
|
-
|
|
234
209
|
setImmediate(() => this._sendQueued(responseId, data));
|
|
235
210
|
}
|
|
236
|
-
|
|
237
211
|
/**
|
|
238
212
|
* Close network connection
|
|
239
213
|
*/
|
|
@@ -242,165 +216,150 @@ class RedisHandler extends EventEmitter {
|
|
|
242
216
|
this.stop = true;
|
|
243
217
|
this.socket.end();
|
|
244
218
|
}
|
|
245
|
-
|
|
246
219
|
/**
|
|
247
220
|
* Return if socket/handler active or closed
|
|
248
|
-
* @returns
|
|
221
|
+
* @returns is Handler/Connection active (not closed)
|
|
249
222
|
*/
|
|
250
223
|
isActive() {
|
|
251
224
|
return !this.stop;
|
|
252
225
|
}
|
|
253
|
-
|
|
254
226
|
/**
|
|
255
227
|
* Encode RESP's Null value to RESP buffer and send out
|
|
256
228
|
* @param responseId ID of the response
|
|
257
229
|
*/
|
|
258
230
|
sendNull(responseId) {
|
|
259
|
-
for (
|
|
231
|
+
for (let i = 0; i < this.activeMultiCalls.length; i++) {
|
|
260
232
|
if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
|
|
261
|
-
this._handleMultiResponse(responseId, i,
|
|
233
|
+
this._handleMultiResponse(responseId, i, respjs_1.default.encodeNull());
|
|
262
234
|
return;
|
|
263
235
|
}
|
|
264
236
|
}
|
|
265
|
-
|
|
266
|
-
this.sendResponse(responseId, Resp.encodeNull());
|
|
237
|
+
this.sendResponse(responseId, respjs_1.default.encodeNull());
|
|
267
238
|
}
|
|
268
|
-
|
|
269
239
|
/**
|
|
270
240
|
* Encode RESP's Null Array value to RESP buffer and send out
|
|
271
241
|
* @param responseId ID of the response
|
|
272
242
|
*/
|
|
273
243
|
sendNullArray(responseId) {
|
|
274
|
-
for (
|
|
244
|
+
for (let i = 0; i < this.activeMultiCalls.length; i++) {
|
|
275
245
|
if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
|
|
276
|
-
this._handleMultiResponse(responseId, i,
|
|
246
|
+
this._handleMultiResponse(responseId, i, respjs_1.default.encodeNullArray());
|
|
277
247
|
return;
|
|
278
248
|
}
|
|
279
249
|
}
|
|
280
|
-
|
|
281
|
-
this.sendResponse(responseId, Resp.encodeNullArray());
|
|
250
|
+
this.sendResponse(responseId, respjs_1.default.encodeNullArray());
|
|
282
251
|
}
|
|
283
|
-
|
|
284
252
|
/**
|
|
285
253
|
* Encode string to RESP buffer and send out
|
|
286
254
|
* @param responseId ID od the response
|
|
287
255
|
* @param str String to encode
|
|
288
256
|
*/
|
|
289
257
|
sendString(responseId, str) {
|
|
290
|
-
for (
|
|
258
|
+
for (let i = 0; i < this.activeMultiCalls.length; i++) {
|
|
291
259
|
if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
|
|
292
|
-
this._handleMultiResponse(responseId, i,
|
|
260
|
+
this._handleMultiResponse(responseId, i, respjs_1.default.encodeString(str));
|
|
293
261
|
return;
|
|
294
262
|
}
|
|
295
263
|
}
|
|
296
|
-
|
|
297
|
-
this.sendResponse(responseId, Resp.encodeString(str));
|
|
264
|
+
this.sendResponse(responseId, respjs_1.default.encodeString(str));
|
|
298
265
|
}
|
|
299
|
-
|
|
300
266
|
/**
|
|
301
267
|
* Encode error object to RESP buffer and send out
|
|
302
268
|
* @param responseId ID of the response
|
|
303
269
|
* @param error Error object with error details to send out
|
|
304
270
|
*/
|
|
305
271
|
sendError(responseId, error) {
|
|
306
|
-
this.log.warn(`${this.socketId} Error from InMemDB: ${error}`);
|
|
307
|
-
|
|
308
|
-
for (const i in this.activeMultiCalls) {
|
|
272
|
+
this.log.warn(`${this.socketId} Error from InMemDB: ${error.stack}`);
|
|
273
|
+
for (let i = 0; i < this.activeMultiCalls.length; i++) {
|
|
309
274
|
if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
|
|
310
|
-
this._handleMultiResponse(responseId, i,
|
|
275
|
+
this._handleMultiResponse(responseId, i, respjs_1.default.encodeError(error));
|
|
311
276
|
return;
|
|
312
277
|
}
|
|
313
278
|
}
|
|
314
|
-
|
|
315
|
-
this.sendResponse(responseId, Resp.encodeError(error));
|
|
279
|
+
this.sendResponse(responseId, respjs_1.default.encodeError(error));
|
|
316
280
|
}
|
|
317
|
-
|
|
318
281
|
/**
|
|
319
282
|
* Encode integer to RESP buffer and send out
|
|
320
283
|
* @param responseId ID of the response
|
|
321
284
|
* @param num Integer to send out
|
|
322
285
|
*/
|
|
323
286
|
sendInteger(responseId, num) {
|
|
324
|
-
for (
|
|
287
|
+
for (let i = 0; i < this.activeMultiCalls.length; i++) {
|
|
325
288
|
if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
|
|
326
|
-
this._handleMultiResponse(responseId, i,
|
|
289
|
+
this._handleMultiResponse(responseId, i, respjs_1.default.encodeInteger(num));
|
|
327
290
|
return;
|
|
328
291
|
}
|
|
329
292
|
}
|
|
330
|
-
|
|
331
|
-
this.sendResponse(responseId, Resp.encodeInteger(num));
|
|
293
|
+
this.sendResponse(responseId, respjs_1.default.encodeInteger(num));
|
|
332
294
|
}
|
|
333
|
-
|
|
334
295
|
/**
|
|
335
296
|
* Encode RESP's bulk string to RESP buffer and send out
|
|
336
297
|
* @param responseId ID of the response
|
|
337
298
|
* @param str String to send out
|
|
338
299
|
*/
|
|
339
300
|
sendBulk(responseId, str) {
|
|
340
|
-
for (
|
|
301
|
+
for (let i = 0; i < this.activeMultiCalls.length; i++) {
|
|
341
302
|
if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
|
|
342
|
-
this._handleMultiResponse(responseId, i,
|
|
303
|
+
this._handleMultiResponse(responseId, i, respjs_1.default.encodeBulk(str));
|
|
343
304
|
return;
|
|
344
305
|
}
|
|
345
306
|
}
|
|
346
|
-
|
|
347
|
-
this.sendResponse(responseId, Resp.encodeBulk(str));
|
|
307
|
+
this.sendResponse(responseId, respjs_1.default.encodeBulk(str));
|
|
348
308
|
}
|
|
349
|
-
|
|
350
309
|
/**
|
|
351
310
|
* Encode RESP's bulk buffer to RESP buffer.
|
|
352
311
|
* @param responseId ID of the response
|
|
353
312
|
* @param buf Buffer to send out
|
|
354
313
|
*/
|
|
355
314
|
sendBufBulk(responseId, buf) {
|
|
356
|
-
for (
|
|
315
|
+
for (let i = 0; i < this.activeMultiCalls.length; i++) {
|
|
357
316
|
if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
|
|
358
|
-
this._handleMultiResponse(responseId, i,
|
|
317
|
+
this._handleMultiResponse(responseId, i, respjs_1.default.encodeBufBulk(buf));
|
|
359
318
|
return;
|
|
360
319
|
}
|
|
361
320
|
}
|
|
362
|
-
|
|
363
|
-
this.sendResponse(responseId, Resp.encodeBufBulk(buf));
|
|
321
|
+
this.sendResponse(responseId, respjs_1.default.encodeBufBulk(buf));
|
|
364
322
|
}
|
|
365
|
-
|
|
366
323
|
/**
|
|
367
324
|
* Encode an Array depending on the type of the elements
|
|
368
325
|
* @param arr Array to encode
|
|
369
|
-
* @returns
|
|
326
|
+
* @returns Array with Buffers with encoded values
|
|
370
327
|
*/
|
|
371
328
|
encodeRespArray(arr) {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
arr[i] = Resp.encodeBufBulk(arr[i]);
|
|
377
|
-
} else if (arr[i] === null) {
|
|
378
|
-
arr[i] = Resp.encodeNull();
|
|
379
|
-
} else if (typeof arr[i] === 'number') {
|
|
380
|
-
arr[i] = Resp.encodeInteger(arr[i]);
|
|
381
|
-
} else {
|
|
382
|
-
arr[i] = Resp.encodeBulk(arr[i]);
|
|
329
|
+
const returnArr = new Array(arr.length);
|
|
330
|
+
arr.forEach((value, i) => {
|
|
331
|
+
if (Array.isArray(value)) {
|
|
332
|
+
returnArr[i] = this.encodeRespArray(value);
|
|
383
333
|
}
|
|
384
|
-
|
|
385
|
-
|
|
334
|
+
else if (Buffer.isBuffer(value)) {
|
|
335
|
+
returnArr[i] = respjs_1.default.encodeBufBulk(value);
|
|
336
|
+
}
|
|
337
|
+
else if (value === null) {
|
|
338
|
+
returnArr[i] = respjs_1.default.encodeNull();
|
|
339
|
+
}
|
|
340
|
+
else if (typeof value === 'number') {
|
|
341
|
+
returnArr[i] = respjs_1.default.encodeInteger(value);
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
returnArr[i] = respjs_1.default.encodeBulk(value);
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
return returnArr;
|
|
386
348
|
}
|
|
387
|
-
|
|
388
349
|
/**
|
|
389
350
|
* Encode a array values to buffers and send out
|
|
390
|
-
* @param
|
|
391
|
-
* @param
|
|
351
|
+
* @param responseId ID of the response
|
|
352
|
+
* @param arr Array to send out
|
|
392
353
|
*/
|
|
393
354
|
sendArray(responseId, arr) {
|
|
394
|
-
for (
|
|
355
|
+
for (let i = 0; i < this.activeMultiCalls.length; i++) {
|
|
395
356
|
if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
|
|
396
|
-
this._handleMultiResponse(responseId, i,
|
|
357
|
+
this._handleMultiResponse(responseId, i, respjs_1.default.encodeArray(this.encodeRespArray(arr)));
|
|
397
358
|
return;
|
|
398
359
|
}
|
|
399
360
|
}
|
|
400
|
-
|
|
401
|
-
this.sendResponse(responseId, Resp.encodeArray(this.encodeRespArray(arr)));
|
|
361
|
+
this.sendResponse(responseId, respjs_1.default.encodeArray(this.encodeRespArray(arr)));
|
|
402
362
|
}
|
|
403
|
-
|
|
404
363
|
/**
|
|
405
364
|
* Handles a 'multi' command
|
|
406
365
|
*
|
|
@@ -414,7 +373,6 @@ class RedisHandler extends EventEmitter {
|
|
|
414
373
|
responseMap: new Map()
|
|
415
374
|
});
|
|
416
375
|
}
|
|
417
|
-
|
|
418
376
|
/**
|
|
419
377
|
* Handles an 'exec' command
|
|
420
378
|
*
|
|
@@ -426,52 +384,42 @@ class RedisHandler extends EventEmitter {
|
|
|
426
384
|
this.sendError(responseId, new Error('EXEC without MULTI'));
|
|
427
385
|
return;
|
|
428
386
|
}
|
|
429
|
-
|
|
430
387
|
this.activeMultiCalls[0].execId = responseId;
|
|
431
388
|
this.activeMultiCalls[0].execCalled = true;
|
|
432
|
-
|
|
433
389
|
// maybe we have all fullfilled yet
|
|
434
390
|
if (this.activeMultiCalls[0].responseCount === this.activeMultiCalls[0].responseIds.length) {
|
|
435
391
|
const multiRespObj = this.activeMultiCalls.shift();
|
|
436
392
|
this._sendExecResponse(multiRespObj);
|
|
437
393
|
}
|
|
438
394
|
}
|
|
439
|
-
|
|
440
395
|
/**
|
|
441
396
|
* Builds up the exec response and sends it
|
|
442
|
-
* @param
|
|
397
|
+
* @param multiObj the multi object to send out
|
|
443
398
|
*
|
|
444
399
|
* @private
|
|
445
400
|
*/
|
|
446
401
|
_sendExecResponse(multiObj) {
|
|
447
402
|
// collect all 'QUEUED' answers
|
|
448
|
-
const queuedStrArr = new Array(multiObj.responseCount).fill(QUEUED_STR_BUF);
|
|
449
|
-
|
|
450
|
-
this._sendQueued(
|
|
451
|
-
multiObj.execId,
|
|
452
|
-
Buffer.concat([OK_STR_BUF, ...queuedStrArr, Resp.encodeArray(Array.from(multiObj.responseMap.values()))])
|
|
453
|
-
);
|
|
403
|
+
const queuedStrArr = new Array(multiObj.responseCount).fill(constants_1.QUEUED_STR_BUF);
|
|
404
|
+
this._sendQueued(multiObj.execId, Buffer.concat([constants_1.OK_STR_BUF, ...queuedStrArr, respjs_1.default.encodeArray(Array.from(multiObj.responseMap.values()))]));
|
|
454
405
|
}
|
|
455
|
-
|
|
456
406
|
/**
|
|
457
407
|
* Handles a multi response
|
|
458
408
|
*
|
|
459
|
-
* @param
|
|
460
|
-
* @param
|
|
461
|
-
* @param
|
|
409
|
+
* @param responseId ID of the response
|
|
410
|
+
* @param index index of the multi call
|
|
411
|
+
* @param buf buffer to include in response
|
|
462
412
|
* @private
|
|
463
413
|
*/
|
|
464
414
|
_handleMultiResponse(responseId, index, buf) {
|
|
465
415
|
this.activeMultiCalls[index].responseMap.set(responseId, buf);
|
|
466
416
|
this.activeMultiCalls[index].responseCount++;
|
|
467
|
-
if (
|
|
468
|
-
this.activeMultiCalls[index].
|
|
469
|
-
this.activeMultiCalls[index].responseCount === this.activeMultiCalls[index].responseIds.length
|
|
470
|
-
) {
|
|
417
|
+
if (this.activeMultiCalls[index].execCalled &&
|
|
418
|
+
this.activeMultiCalls[index].responseCount === this.activeMultiCalls[index].responseIds.length) {
|
|
471
419
|
const multiRespObj = this.activeMultiCalls.splice(index, 1)[0];
|
|
472
420
|
this._sendExecResponse(multiRespObj);
|
|
473
421
|
}
|
|
474
422
|
}
|
|
475
423
|
}
|
|
476
|
-
|
|
477
|
-
|
|
424
|
+
exports.RedisHandler = RedisHandler;
|
|
425
|
+
//# sourceMappingURL=redisHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redisHandler.js","sourceRoot":"","sources":["../../src/lib/redisHandler.ts"],"names":[],"mappings":";;;;;;AACA,4BAA4B;AAC5B,oDAA0B;AAC1B,mCAAsC;AACtC,2CAAyD;AAiDzD;;;GAGG;AACH,MAAa,YAAa,SAAQ,qBAAY;IAa1C;;;;OAIG;IACH,YAAY,MAAc,EAAE,OAA4B;QACpD,KAAK,EAAE,CAAC;QAER,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC;QAClC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC;QACvC,IAAI,IAAI,CA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": {
|
|
8
|
-
"@iobroker/js-controller-common": "4.0.
|
|
8
|
+
"@iobroker/js-controller-common": "4.1.0-alpha.0-20220819-74ceeddc",
|
|
9
9
|
"deep-clone": "^3.0.3",
|
|
10
|
-
"fs-extra": "^10.
|
|
10
|
+
"fs-extra": "^10.1.0",
|
|
11
11
|
"respjs": "^4.2.0"
|
|
12
12
|
},
|
|
13
13
|
"keywords": [
|
|
@@ -25,15 +25,31 @@
|
|
|
25
25
|
"type": "git",
|
|
26
26
|
"url": "https://github.com/ioBroker/ioBroker.js-controller/packages/db-base"
|
|
27
27
|
},
|
|
28
|
-
"scripts": {
|
|
29
|
-
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsc -b tsconfig.build.json"
|
|
30
|
+
},
|
|
31
|
+
"main": "build/index.js",
|
|
30
32
|
"license": "MIT",
|
|
31
33
|
"publishConfig": {
|
|
32
34
|
"access": "public"
|
|
33
35
|
},
|
|
36
|
+
"exports": {
|
|
37
|
+
".": "./build/index.js",
|
|
38
|
+
"./package.json": "./package.json",
|
|
39
|
+
"./inMemFileDB": "./build/lib/inMemFileDB.js"
|
|
40
|
+
},
|
|
41
|
+
"types": "build/index.d.ts",
|
|
42
|
+
"typesVersions": {
|
|
43
|
+
"*": {
|
|
44
|
+
"inMemFileDB": [
|
|
45
|
+
"build/lib/inMemFileDB"
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
},
|
|
34
49
|
"files": [
|
|
35
|
-
"lib/",
|
|
36
|
-
"index.js"
|
|
50
|
+
"build/lib/",
|
|
51
|
+
"build/index.js",
|
|
52
|
+
"build/index.d.ts"
|
|
37
53
|
],
|
|
38
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "febfe24ecb050ec02f848cc869d84aa30d69c615"
|
|
39
55
|
}
|
package/index.js
DELETED
package/lib/constants.js
DELETED
package/lib/tools.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
const { tools } = require('@iobroker/js-controller-common');
|
|
2
|
-
|
|
3
|
-
module.exports = tools;
|
|
4
|
-
const controllerDir = tools.getControllerDir() || __dirname;
|
|
5
|
-
module.exports.getControllerDir = () => controllerDir;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Checks if the given callback is a function and if so calls it with the given error and parameter immediately, else a resolved or rejected Promise is returned. Redis-Error "Connection is closed." is converted into ERROR_DB_CLOSED
|
|
9
|
-
*
|
|
10
|
-
* @param {((error: Error | null | undefined, ...args: any[]) => void) | null | undefined} callback - callback function to be executed
|
|
11
|
-
* @param {Error | string | null | undefined} error - error which will be used by the callback function. If callback is not a function and
|
|
12
|
-
* error is given, a rejected Promise is returned. If error is given but it is not an instance of Error, it is converted into one.
|
|
13
|
-
* @param {...any} args - as many arguments as needed, which will be returned by the callback function or by the Promise
|
|
14
|
-
* @returns {Promise<any>} - if Promise is resolved with multiple arguments, an array is returned
|
|
15
|
-
*/
|
|
16
|
-
module.exports.maybeCallbackWithRedisError = (callback, error, ...args) => {
|
|
17
|
-
if (error instanceof Error && error.message.includes('Connection is closed')) {
|
|
18
|
-
error.message = module.exports.ERRORS.ERROR_DB_CLOSED;
|
|
19
|
-
}
|
|
20
|
-
return module.exports.maybeCallbackWithError(callback, error, ...args);
|
|
21
|
-
};
|