Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@iobroker/db-base

Package Overview
Dependencies
Maintainers
6
Versions
424
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@iobroker/db-base - npm Package Compare versions

Comparing version 4.0.0-alpha.57-20220128-980c8b74 to 4.0.0-alpha.58-20220128-2cba6d0d

125

lib/redisHandler.js

@@ -27,6 +27,7 @@ const Resp = require('respjs');

this.socketId = this.logScope + socket.remoteAddress + ':' + socket.remotePort;
this.socketId = `${this.logScope + socket.remoteAddress}:${socket.remotePort}`;
this.initialized = false;
this.stop = false;
this.activeMultiCalls = [];
this.writeQueue = [];

@@ -116,2 +117,6 @@

if (command === 'multi') {
if (this.activeMultiCalls.length && !this.activeMultiCalls[0].execCalled) {
// should never happen
this.log.warn(`${this.socketId} Conflicting multi call`);
}
this._handleMulti();

@@ -122,7 +127,7 @@ return;

// multi active and exec not called yet
if (this.multiActive && !this.execCalled && command !== 'exec') {
if (this.activeMultiCalls.length && !this.activeMultiCalls[0].execCalled && command !== 'exec') {
// store all response ids so we know which need to be in the multi call
this.multiResponseIds.push(responseId);
this.activeMultiCalls[0].responseIds.push(responseId);
// add it for the correct order will be overwritten with correct response
this.multiResponseMap.set(responseId, null);
this.activeMultiCalls[0].responseMap.set(responseId, null);
} else {

@@ -257,5 +262,7 @@ // multi response ids should not be pushed - we will answer combined

sendNull(responseId) {
if (this.multiActive && this.multiResponseIds.includes(responseId)) {
this._handleMultiResponse(responseId, Resp.encodeNull());
return;
for (const i in this.activeMultiCalls) {
if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
this._handleMultiResponse(responseId, i, Resp.encodeNull());
return;
}
}

@@ -271,5 +278,7 @@

sendNullArray(responseId) {
if (this.multiActive && this.multiResponseIds.includes(responseId)) {
this._handleMultiResponse(responseId, Resp.encodeNullArray());
return;
for (const i in this.activeMultiCalls) {
if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
this._handleMultiResponse(responseId, i, Resp.encodeNullArray());
return;
}
}

@@ -286,5 +295,7 @@

sendString(responseId, str) {
if (this.multiActive && this.multiResponseIds.includes(responseId)) {
this._handleMultiResponse(responseId, Resp.encodeString(str));
return;
for (const i in this.activeMultiCalls) {
if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
this._handleMultiResponse(responseId, i, Resp.encodeString(str));
return;
}
}

@@ -303,5 +314,7 @@

if (this.multiActive && this.multiResponseIds.includes(responseId)) {
this._handleMultiResponse(responseId, Resp.encodeError(error));
return;
for (const i in this.activeMultiCalls) {
if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
this._handleMultiResponse(responseId, i, Resp.encodeError(error));
return;
}
}

@@ -318,5 +331,7 @@

sendInteger(responseId, num) {
if (this.multiActive && this.multiResponseIds.includes(responseId)) {
this._handleMultiResponse(responseId, Resp.encodeInteger(num));
return;
for (const i in this.activeMultiCalls) {
if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
this._handleMultiResponse(responseId, i, Resp.encodeInteger(num));
return;
}
}

@@ -333,5 +348,7 @@

sendBulk(responseId, str) {
if (this.multiActive && this.multiResponseIds.includes(responseId)) {
this._handleMultiResponse(responseId, Resp.encodeBulk(str));
return;
for (const i in this.activeMultiCalls) {
if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
this._handleMultiResponse(responseId, i, Resp.encodeBulk(str));
return;
}
}

@@ -348,5 +365,7 @@

sendBufBulk(responseId, buf) {
if (this.multiActive && this.multiResponseIds.includes(responseId)) {
this._handleMultiResponse(responseId, Resp.encodeBufBulk(buf));
return;
for (const i in this.activeMultiCalls) {
if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
this._handleMultiResponse(responseId, i, Resp.encodeBufBulk(buf));
return;
}
}

@@ -381,9 +400,11 @@

* Encode a array values to buffers and send out
* @param {string} responseId ID of the response
* @param {number} responseId ID of the response
* @param {any[]} arr Array to send out
*/
sendArray(responseId, arr) {
if (this.multiActive && this.multiResponseIds.includes(responseId)) {
this._handleMultiResponse(responseId, Resp.encodeArray(this.encodeRespArray(arr)));
return;
for (const i in this.activeMultiCalls) {
if (this.activeMultiCalls[i].responseIds.includes(responseId)) {
this._handleMultiResponse(responseId, i, Resp.encodeArray(this.encodeRespArray(arr)));
return;
}
}

@@ -400,11 +421,8 @@

_handleMulti() {
if (this.multiActive) {
this.log.warn(`${this.socketId} Conflicting multi call`);
}
this.multiActive = true;
this.execCalled = false;
this.multiResponseIds = [];
this.multiResponseCount = 0;
this.multiResponseMap = new Map();
this.activeMultiCalls.unshift({
responseIds: [],
execCalled: false,
responseCount: 0,
responseMap: new Map()
});
}

@@ -419,8 +437,9 @@

_handleExec(responseId) {
this.execCalled = true;
this.execId = responseId;
this.activeMultiCalls[0].execId = responseId;
this.activeMultiCalls[0].execCalled = true;
// maybe we have all fullfilled yet
if (this.multiResponseCount === this.multiResponseIds.length) {
this._sendExecReponse();
if (this.activeMultiCalls[0].responseCount === this.activeMultiCalls[0].responseIds.length) {
const multiRespObj = this.activeMultiCalls.shift();
this._sendExecResponse(multiRespObj);
}

@@ -431,13 +450,13 @@ }

* Builds up the exec response and sends it
* @param {Record<string, any>} multiObj the multi object to send out
*
* @private
*/
_sendExecReponse() {
this.multiActive = false;
_sendExecResponse(multiObj) {
// collect all 'QUEUED' answers
const queuedStrArr = new Array(this.multiResponseCount).fill(QUEUED_STR_BUF);
const queuedStrArr = new Array(multiObj.responseCount).fill(QUEUED_STR_BUF);
this._sendQueued(
this.execId,
Buffer.concat([OK_STR_BUF, ...queuedStrArr, Resp.encodeArray(Array.from(this.multiResponseMap.values()))])
multiObj.execId,
Buffer.concat([OK_STR_BUF, ...queuedStrArr, Resp.encodeArray(Array.from(multiObj.responseMap.values()))])
);

@@ -450,10 +469,12 @@ }

* @param {number} responseId ID of the response
* @param {number} index index of the multi call
* @param {Buffer} buf buffer to include in response
* @private
*/
_handleMultiResponse(responseId, buf) {
this.multiResponseMap.set(responseId, buf);
this.multiResponseCount++;
if (this.execCalled && this.multiResponseCount === this.multiResponseIds.length) {
this._sendExecReponse();
_handleMultiResponse(responseId, index, buf) {
this.activeMultiCalls[index].responseMap.set(responseId, buf);
this.activeMultiCalls[index].responseCount++;
if (this.activeMultiCalls[index].responseCount === this.activeMultiCalls[index].responseIds.length) {
const multiRespObj = this.activeMultiCalls.splice(index, 1)[0];
this._sendExecResponse(multiRespObj);
}

@@ -460,0 +481,0 @@ }

{
"name": "@iobroker/db-base",
"version": "4.0.0-alpha.57-20220128-980c8b74",
"version": "4.0.0-alpha.58-20220128-2cba6d0d",
"engines": {

@@ -8,3 +8,3 @@ "node": ">=12.0.0"

"dependencies": {
"@iobroker/js-controller-common": "4.0.0-alpha.57-20220128-980c8b74",
"@iobroker/js-controller-common": "4.0.0-alpha.58-20220128-2cba6d0d",
"deep-clone": "^3.0.3",

@@ -39,3 +39,3 @@ "fs-extra": "^10.0.0",

],
"gitHead": "63f44e67f57bd8c821791e8f67714d6bc35bac4b"
"gitHead": "1a3a34037fd5ad4a610490cf50b9f66193900e96"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc