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

@iobroker/db-states-redis

Package Overview
Dependencies
Maintainers
6
Versions
431
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@iobroker/db-states-redis - npm Package Compare versions

Comparing version 4.0.0-alpha.3-20210903-1d3954b5 to 4.0.0-alpha.30-20211220-ce617590

2

index.js

@@ -5,4 +5,4 @@ module.exports = {

getDefaultPort: host => {
return (host.includes(',')) ? 26379 : 6379;
return host.includes(',') ? 26379 : 6379;
}
};

@@ -25,3 +25,10 @@ /**

function bufferJsonDecoder(key, value) {
if (value && typeof value === 'object' && typeof value.type === 'string' && value.type === 'Buffer' && value.data && Array.isArray(value.data)) {
if (
value &&
typeof value === 'object' &&
typeof value.type === 'string' &&
value.type === 'Buffer' &&
value.data &&
Array.isArray(value.data)
) {
return Buffer.from(value.data);

@@ -33,3 +40,2 @@ }

class StateRedisClient {
constructor(settings) {

@@ -42,2 +48,3 @@ this.settings = settings || {};

this.namespaceSession = (this.settings.namespaceSession || 'session') + '.';
this.metaNamespace = (this.settings.metaNamespace || 'meta') + '.';

@@ -48,2 +55,4 @@ this.globalMessageId = Math.round(Math.random() * 100000000);

this.supportedProtocolVersions = ['4'];
this.stop = false;

@@ -61,2 +70,27 @@ this.client = null;

/**
* Checks if we are allowed to start and sets the protocol version accordingly
*
* @returns {Promise<void>}
* @private
*/
async _determineProtocolVersion() {
const protoVersion = await this.client.get(`${this.metaNamespace}states.protocolVersion`);
if (!protoVersion) {
// if no proto version existent yet, we set ours
const highestVersion = Math.max(...this.supportedProtocolVersions);
await this.setProtocolVersion(highestVersion);
this.activeProtocolVersion = highestVersion.toString();
return;
}
// check if we can support this version
if (this.supportedProtocolVersions.includes(protoVersion)) {
this.activeProtocolVersion = protoVersion;
} else {
throw new Error(`This host does not support protocol version "${protoVersion}"`);
}
}
connectDb() {

@@ -68,4 +102,2 @@ this.settings.connection = this.settings.connection || {};

const ioRegExp = new RegExp('^' + this.namespaceRedis.replace(/\./g, '\\.') + '[_A-Za-z0-9ÄÖÜäöüа-яА-Я]+'); // io.[_A-Za-z0-9]+
let ready = false;

@@ -123,7 +155,11 @@ let initError = false;

if (this.settings.connection.port === 0) { // Port = 0 means unix socket
if (this.settings.connection.port === 0) {
// Port = 0 means unix socket
// initiate a unix socket connection
this.settings.connection.options.path = this.settings.connection.host;
this.log.debug(`${this.namespace} Redis States: Use File Socket for connection: ${this.settings.connection.options.path}`);
} else if (Array.isArray(this.settings.connection.host)) { // Host is an array means we use a sentinel
this.log.debug(
`${this.namespace} Redis States: Use File Socket for connection: ${this.settings.connection.options.path}`
);
} else if (Array.isArray(this.settings.connection.host)) {
// Host is an array means we use a sentinel
const defaultPort = Array.isArray(this.settings.connection.port) ? null : this.settings.connection.port;

@@ -134,8 +170,16 @@ this.settings.connection.options.sentinels = this.settings.connection.host.map((redisNode, idx) => ({

}));
this.settings.connection.options.name = this.settings.connection.sentinelName ? this.settings.connection.sentinelName : 'mymaster';
this.log.debug(`${this.namespace} Redis States: Use Sentinel for connection: ${this.settings.connection.options.name}, ${JSON.stringify(this.settings.connection.options.sentinels)}`);
this.settings.connection.options.name = this.settings.connection.sentinelName
? this.settings.connection.sentinelName
: 'mymaster';
this.log.debug(
`${this.namespace} Redis States: Use Sentinel for connection: ${
this.settings.connection.options.name
}, ${JSON.stringify(this.settings.connection.options.sentinels)}`
);
} else {
this.settings.connection.options.host = this.settings.connection.host;
this.settings.connection.options.port = this.settings.connection.port;
this.log.debug(`${this.namespace} Redis States: Use Redis connection: ${this.settings.connection.options.host}:${this.settings.connection.options.port}`);
this.log.debug(
`${this.namespace} Redis States: Use Redis connection: ${this.settings.connection.options.host}:${this.settings.connection.options.port}`
);
}

@@ -148,3 +192,4 @@ if (this.settings.connection.options.db === undefined) {

}
this.settings.connection.options.password = this.settings.connection.options.auth_pass || this.settings.connection.pass || null;
this.settings.connection.options.password =
this.settings.connection.options.auth_pass || this.settings.connection.pass || null;
this.settings.connection.options.autoResubscribe = false; // We do our own resubscribe because other sometimes not work

@@ -157,3 +202,6 @@ // REDIS does not allow whitespaces, we have some because of pid

this.client.on('error', error => {
this.settings.connection.enhancedLogging && this.log.silly(`${this.namespace} Redis ERROR States: (${this.stop}) ${error.message} / ${error.stack}`);
this.settings.connection.enhancedLogging &&
this.log.silly(
`${this.namespace} Redis ERROR States: (${this.stop}) ${error.message} / ${error.stack}`
);
if (this.stop) {

@@ -166,3 +214,5 @@ return;

if (error.message.startsWith('Protocol error, got "H" as reply type byte.')) {
this.log.error(`${this.namespace} Could not connect to states database at ${this.settings.connection.options.host}:${this.settings.connection.options.port} (invalid protocol). Please make sure the configured IP and port points to a host running JS-Controller >= 2.0. and that the port is not occupied by other software!`);
this.log.error(
`${this.namespace} Could not connect to states database at ${this.settings.connection.options.host}:${this.settings.connection.options.port} (invalid protocol). Please make sure the configured IP and port points to a host running JS-Controller >= 2.0. and that the port is not occupied by other software!`
);
}

@@ -176,3 +226,4 @@ return;

this.client.on('end', () => {
this.settings.connection.enhancedLogging && this.log.silly(`${this.namespace} States-Redis Event end (stop=${this.stop})`);
this.settings.connection.enhancedLogging &&
this.log.silly(`${this.namespace} States-Redis Event end (stop=${this.stop})`);
if (ready && typeof this.settings.disconnected === 'function') {

@@ -184,3 +235,4 @@ this.settings.disconnected();

this.client.on('connect', () => {
this.settings.connection.enhancedLogging && this.log.silly(`${this.namespace} States-Redis Event connect (stop=${this.stop})`);
this.settings.connection.enhancedLogging &&
this.log.silly(`${this.namespace} States-Redis Event connect (stop=${this.stop})`);
connected = true;

@@ -194,3 +246,4 @@ if (errorLogged) {

this.client.on('close', () => {
this.settings.connection.enhancedLogging && this.log.silly(`${this.namespace} States-Redis Event close (stop=${this.stop})`);
this.settings.connection.enhancedLogging &&
this.log.silly(`${this.namespace} States-Redis Event close (stop=${this.stop})`);
//if (ready && typeof this.settings.disconnected === 'function') this.settings.disconnected();

@@ -203,5 +256,11 @@ });

}
this.settings.connection.enhancedLogging && this.log.silly(`${this.namespace} States-Redis Event reconnect (reconnectCounter=${reconnectCounter}, stop=${this.stop})`);
if (reconnectCounter > 2) { // fallback logic for nodejs <10
this.log.error(`${this.namespace} The DB port ${this.settings.connection.options.port} is occupied by something that is not a Redis protocol server. Please check other software running on this port or, if you use iobroker, make sure to update to js-controller 2.0 or higher!`);
this.settings.connection.enhancedLogging &&
this.log.silly(
`${this.namespace} States-Redis Event reconnect (reconnectCounter=${reconnectCounter}, stop=${this.stop})`
);
if (reconnectCounter > 2) {
// fallback logic for nodejs <10
this.log.error(
`${this.namespace} The DB port ${this.settings.connection.options.port} is occupied by something that is not a Redis protocol server. Please check other software running on this port or, if you use iobroker, make sure to update to js-controller 2.0 or higher!`
);
return;

@@ -214,3 +273,4 @@ }

this.client.on('ready', async () => {
this.settings.connection.enhancedLogging && this.log.silly(`${this.namespace} States-Redis Event ready (stop=${this.stop})`);
this.settings.connection.enhancedLogging &&
this.log.silly(`${this.namespace} States-Redis Event ready (stop=${this.stop})`);
if (this.stop) {

@@ -225,5 +285,7 @@ return;

try {
await this.client.config('set', ['notify-keyspace-events', 'Exe']);// enable Expiry/Evicted events in server
await this.client.config('set', ['notify-keyspace-events', 'Exe']); // enable Expiry/Evicted events in server
} catch (e) {
this.log.warn(`${this.namespace} Unable to enable Expiry Keyspace events from Redis Server: ${e.message}`);
this.log.warn(
`${this.namespace} Unable to enable Expiry Keyspace events from Redis Server: ${e.message}`
);
}

@@ -238,6 +300,26 @@

setImmediate(() => {
this.log.silly(`${this.namespace} States system redis pmessage ${pattern}/${channel}:${message}`);
this.log.silly(
`${this.namespace} States system redis pmessage ${pattern}/${channel}:${message}`
);
if (channel.startsWith(this.metaNamespace)) {
if (
channel === `${this.metaNamespace}states.protocolVersion` &&
message !== this.activeProtocolVersion
) {
if (typeof this.settings.disconnected === 'function') {
// protocol version has changed, restart controller
this.log.info(
`${this.namespace} States protocol version has changed, disconnecting!`
);
this.settings.disconnected();
}
}
return;
}
try {
message = message ? JSON.parse(message, message.includes('"Buffer"') ? bufferJsonDecoder: undefined) : null;
message = message
? JSON.parse(message, message.includes('"Buffer"') ? bufferJsonDecoder : undefined)
: null;
} catch {

@@ -249,3 +331,3 @@ this.log.warn(`${this.namespace} Cannot parse system pmessage "${message}"`);

try {
if (ioRegExp.test(channel)) {
if (channel.startsWith(this.namespaceRedis) && channel.length > this.namespaceRedisL) {
onChange(channel.substring(this.namespaceRedisL), message);

@@ -256,3 +338,7 @@ } else {

} catch (e) {
this.log.warn(`${this.namespace} States system pmessage ${channel} ${JSON.stringify(message)} ${e.message}`);
this.log.warn(
`${this.namespace} States system pmessage ${channel} ${JSON.stringify(message)} ${
e.message
}`
);
this.log.warn(`${this.namespace} ${e.stack}`);

@@ -267,6 +353,13 @@ }

setImmediate(() => {
this.log.silly(this.namespace + ' redis message expired/evicted ' + channel + ':' + message);
this.log.silly(
this.namespace + ' redis message expired/evicted ' + channel + ':' + message
);
try {
if (channel === `__keyevent@${this.settings.connection.options.db}__:evicted`) {
this.log.warn(this.namespace + ' Redis has evicted state ' + message + '. Please check your maxMemory settings for your redis instance!');
this.log.warn(
this.namespace +
' Redis has evicted state ' +
message +
'. Please check your maxMemory settings for your redis instance!'
);
} else if (channel !== `__keyevent@${this.settings.connection.options.db}__:expired`) {

@@ -278,3 +371,5 @@ this.log.warn(`${this.namespace} Unknown user message ${channel} ${message}`);

// Find deleted states and notify user
const found = Object.values(this.subSystem.ioBrokerSubscriptions).find(regex => regex !== true && regex.test(message));
const found = Object.values(this.subSystem.ioBrokerSubscriptions).find(
regex => regex !== true && regex.test(message)
);
found && onChange(message.substring(this.namespaceRedisL), null);

@@ -284,3 +379,5 @@ }

// Find deleted states and notify user
const found = Object.values(this.sub.ioBrokerSubscriptions).find(regex => regex !== true && regex.test(message));
const found = Object.values(this.sub.ioBrokerSubscriptions).find(
regex => regex !== true && regex.test(message)
);
found && onChangeUser(message.substring(this.namespaceRedisL), null);

@@ -292,6 +389,8 @@ }

}
}));
})
);
}
this.subSystem.on('end', () => {
this.settings.connection.enhancedLogging && this.log.silly(`${this.namespace} States-Redis System Event end sub (stop=${this.stop})`);
this.settings.connection.enhancedLogging &&
this.log.silly(`${this.namespace} States-Redis System Event end sub (stop=${this.stop})`);
ready && typeof this.settings.disconnected === 'function' && this.settings.disconnected();

@@ -304,3 +403,6 @@ });

}
this.settings.connection.enhancedLogging && this.log.silly(`${this.namespace} Sub-Client States System No redis connection: ${JSON.stringify(error)}`);
this.settings.connection.enhancedLogging &&
this.log.silly(
`${this.namespace} Sub-Client States System No redis connection: ${JSON.stringify(error)}`
);
});

@@ -310,9 +412,18 @@

this.subSystem.on('connect', () =>
this.log.silly(`${this.namespace} PubSub client States-Redis System Event connect (stop=${this.stop})`));
this.log.silly(
`${this.namespace} PubSub client States-Redis System Event connect (stop=${this.stop})`
)
);
this.subSystem.on('close', () =>
this.log.silly(`${this.namespace} PubSub client States-Redis System Event close (stop=${this.stop})`));
this.log.silly(
`${this.namespace} PubSub client States-Redis System Event close (stop=${this.stop})`
)
);
this.subSystem.on('reconnecting', reconnectCounter =>
this.log.silly(`${this.namespace} PubSub client States-Redis System Event reconnect (reconnectCounter=${reconnectCounter}, stop=${this.stop})`));
this.log.silly(
`${this.namespace} PubSub client States-Redis System Event reconnect (reconnectCounter=${reconnectCounter}, stop=${this.stop})`
)
);
}

@@ -322,18 +433,45 @@

try {
this.subSystem && await this.subSystem.subscribe(`__keyevent@${this.settings.connection.options.db}__:expired`);
this.subSystem &&
(await this.subSystem.subscribe(
`__keyevent@${this.settings.connection.options.db}__:expired`
));
} catch (e) {
this.log.warn(`${this.namespace} Unable to subscribe to expiry Keyspace events from Redis Server: ${e.message}`);
this.log.warn(
`${this.namespace} Unable to subscribe to expiry Keyspace events from Redis Server: ${e.message}`
);
}
try {
this.subSystem && await this.subSystem.subscribe(`__keyevent@${this.settings.connection.options.db}__:evicted`);
this.subSystem &&
(await this.subSystem.subscribe(
`__keyevent@${this.settings.connection.options.db}__:evicted`
));
} catch (e) {
this.log.warn(`${this.namespace} Unable to subscribe to evicted Keyspace events from Redis Server: ${e.message}`);
this.log.warn(
`${this.namespace} Unable to subscribe to evicted Keyspace events from Redis Server: ${e.message}`
);
}
// subscribe to meta changes
try {
this.subSystem && (await this.subSystem.psubscribe(`${this.metaNamespace}*`));
} catch (e) {
this.log.warn(
`${this.namespace} Unable to subscribe to meta namespace "${this.metaNamespace}" changes: ${e.message}`
);
}
if (--initCounter < 1) {
if (this.settings.connection.port === 0) {
this.log.debug(`${this.namespace} States ${ready ? 'system re' : ''}connected to redis: ${this.settings.connection.host}`);
this.log.debug(
`${this.namespace} States ${ready ? 'system re' : ''}connected to redis: ${
this.settings.connection.host
}`
);
} else {
this.log.debug(`${this.namespace} States ${ready ? 'system re' : ''}connected to redis: ${this.settings.connection.host}:${this.settings.connection.port}`);
this.log.debug(
`${this.namespace} States ${ready ? 'system re' : ''}connected to redis: ${
this.settings.connection.host
}:${this.settings.connection.port}`
);
}

@@ -368,3 +506,5 @@ !ready && typeof this.settings.connected === 'function' && this.settings.connected();

try {
message = message ? JSON.parse(message, message.includes('"Buffer"') ? bufferJsonDecoder: undefined) : null;
message = message
? JSON.parse(message, message.includes('"Buffer"') ? bufferJsonDecoder : undefined)
: null;
} catch {

@@ -376,3 +516,3 @@ this.log.warn(`${this.namespace} Cannot parse user pmessage "${message}"`);

try {
if (ioRegExp.test(channel)) {
if (channel.startsWith(this.namespaceRedis) && channel.length > this.namespaceRedisL) {
onChangeUser(channel.substring(this.namespaceRedisL), message);

@@ -383,3 +523,7 @@ } else {

} catch (e) {
this.log.warn(`${this.namespace} States user pmessage ${channel} ${JSON.stringify(message)} ${e.message}`);
this.log.warn(
`${this.namespace} States user pmessage ${channel} ${JSON.stringify(message)} ${
e.message
}`
);
this.log.warn(`${this.namespace} ${e.stack}`);

@@ -391,3 +535,4 @@ }

this.sub.on('end', () => {
this.settings.connection.enhancedLogging && this.log.silly(`${this.namespace} States-Redis User Event end sub (stop=${this.stop})`);
this.settings.connection.enhancedLogging &&
this.log.silly(`${this.namespace} States-Redis User Event end sub (stop=${this.stop})`);
if (ready && typeof this.settings.disconnected === 'function') {

@@ -403,3 +548,5 @@ this.settings.disconnected();

if (this.settings.connection.enhancedLogging) {
this.log.silly(`${this.namespace} Sub-Client States User No redis connection: ${JSON.stringify(error)}`);
this.log.silly(
`${this.namespace} Sub-Client States User No redis connection: ${JSON.stringify(error)}`
);
}

@@ -410,11 +557,17 @@ });

this.sub.on('connect', () => {
this.log.silly(`${this.namespace} PubSub client States-Redis User Event connect (stop=${this.stop})`);
this.log.silly(
`${this.namespace} PubSub client States-Redis User Event connect (stop=${this.stop})`
);
});
this.sub.on('close', () => {
this.log.silly(`${this.namespace} PubSub client States-Redis User Event close (stop=${this.stop})`);
this.log.silly(
`${this.namespace} PubSub client States-Redis User Event close (stop=${this.stop})`
);
});
this.sub.on('reconnecting', reconnectCounter => {
this.log.silly(`${this.namespace} PubSub client States-Redis User Event reconnect (reconnectCounter=${reconnectCounter}, stop=${this.stop})`);
this.log.silly(
`${this.namespace} PubSub client States-Redis User Event reconnect (reconnectCounter=${reconnectCounter}, stop=${this.stop})`
);
});

@@ -426,5 +579,13 @@ }

if (this.settings.connection.port === 0) {
this.log.debug(`${this.namespace} States ${ready ? 'user re' : ''}connected to redis: ${this.settings.connection.host}`);
this.log.debug(
`${this.namespace} States ${ready ? 'user re' : ''}connected to redis: ${
this.settings.connection.host
}`
);
} else {
this.log.debug(`${this.namespace} States ${ready ? 'user re' : ''}connected to redis: ${this.settings.connection.host}:${this.settings.connection.port}`);
this.log.debug(
`${this.namespace} States ${ready ? 'user re' : ''}connected to redis: ${
this.settings.connection.host
}:${this.settings.connection.port}`
);
}

@@ -445,7 +606,22 @@ !ready && typeof this.settings.connected === 'function' && this.settings.connected();

try {
await this._determineProtocolVersion();
} catch (e) {
this.log.error(`${this.namespace} ${e.message}`);
throw new Error('States DB is not allowed to start in the current Multihost environment');
}
if (initCounter < 1) {
if (this.settings.connection.port === 0) {
this.log.debug(`${this.namespace} States ${ready ? 'client re' : ''}connected to redis: ${this.settings.connection.host}`);
this.log.debug(
`${this.namespace} States ${ready ? 'client re' : ''}connected to redis: ${
this.settings.connection.host
}`
);
} else {
this.log.debug(`${this.namespace} States ${ready ? 'client re' : ''}connected to redis: ${this.settings.connection.host}:${this.settings.connection.port}`);
this.log.debug(
`${this.namespace} States ${ready ? 'client re' : ''}connected to redis: ${
this.settings.connection.host
}:${this.settings.connection.port}`
);
}

@@ -455,3 +631,2 @@ !ready && typeof this.settings.connected === 'function' && this.settings.connected();

}
});

@@ -461,3 +636,3 @@ }

getStatus() {
return {type: 'redis', server: false};
return { type: 'redis', server: false };
}

@@ -526,3 +701,3 @@

if (!oldObj) {
oldObj = {val: null};
oldObj = { val: null };
} else {

@@ -533,3 +708,3 @@ try {

this.log.warn(`${this.namespace} Cannot parse "${oldObj}"`);
oldObj = {val: null};
oldObj = { val: null };
}

@@ -551,5 +726,5 @@ }

if (state.ts !== undefined) {
obj.ts = (state.ts < 946681200000) ? state.ts * 1000 : state.ts; // if less 2000.01.01 00:00:00
obj.ts = state.ts < 946681200000 ? state.ts * 1000 : state.ts; // if less 2000.01.01 00:00:00
} else {
obj.ts = (new Date()).getTime();
obj.ts = new Date().getTime();
}

@@ -595,3 +770,4 @@

// publish event in redis
this.settings.connection.enhancedLogging && this.log.silly(`${this.namespace} redis publish ${this.namespaceRedis}${id} ${objString}`);
this.settings.connection.enhancedLogging &&
this.log.silly(`${this.namespace} redis publish ${this.namespaceRedis}${id} ${objString}`);
await this.client.publish(this.namespaceRedis + id, objString);

@@ -606,3 +782,4 @@ return tools.maybeCallbackWithError(callback, null, id);

// publish event in redis
this.settings.connection.enhancedLogging && this.log.silly(`${this.namespace} redis publish ${this.namespaceRedis}${id} ${objString}`);
this.settings.connection.enhancedLogging &&
this.log.silly(`${this.namespace} redis publish ${this.namespaceRedis}${id} ${objString}`);
await this.client.publish(this.namespaceRedis + id, objString);

@@ -700,6 +877,2 @@ return tools.maybeCallbackWithError(callback, null, id);

async getStates(keys, callback, dontModify) {
if (typeof callback !== 'function') {
this.log.warn(`${this.namespace} redis getStates no callback`);
return;
}
if (!keys || !Array.isArray(keys)) {

@@ -724,5 +897,6 @@ return tools.maybeCallbackWithError(callback, 'no keys', null);

obj = await this.client.mget(_keys);
this.settings.connection.enhancedLogging && this.log.silly(`${this.namespace} redis mget ${(!obj) ? 0 : obj.length} ${_keys.length}`);
this.settings.connection.enhancedLogging &&
this.log.silly(`${this.namespace} redis mget ${!obj ? 0 : obj.length} ${_keys.length}`);
} catch (e) {
this.log.warn(`${this.namespace} redis mget ${(!obj) ? 0 : obj.length} ${_keys.length}, err: ${e.message}`);
this.log.warn(`${this.namespace} redis mget ${!obj ? 0 : obj.length} ${_keys.length}, err: ${e.message}`);
}

@@ -799,3 +973,2 @@ const result = [];

}
}

@@ -847,3 +1020,4 @@ if (this.subSystem) {

}
this.settings.connection.enhancedLogging && this.log.silly(`${this.namespace} redis keys ${obj.length} ${pattern}`);
this.settings.connection.enhancedLogging &&
this.log.silly(`${this.namespace} redis keys ${obj.length} ${pattern}`);
if (obj && !dontModify) {

@@ -879,6 +1053,9 @@ const len = this.namespaceRedisL;

this.settings.connection.enhancedLogging && this.log.silly(`${this.namespace} redis psubscribe ${this.namespaceRedis}${pattern}`);
this.settings.connection.enhancedLogging &&
this.log.silly(`${this.namespace} redis psubscribe ${this.namespaceRedis}${pattern}`);
try {
await subClient.psubscribe(this.namespaceRedis + pattern);
subClient.ioBrokerSubscriptions[this.namespaceRedis + pattern] = new RegExp(tools.pattern2RegEx(this.namespaceRedis + pattern));
subClient.ioBrokerSubscriptions[this.namespaceRedis + pattern] = new RegExp(
tools.pattern2RegEx(this.namespaceRedis + pattern)
);
return tools.maybeCallback(callback);

@@ -915,3 +1092,4 @@ } catch (e) {

this.settings.connection.enhancedLogging && this.log.silly(`${this.namespace} redis punsubscribe ${this.namespaceRedis}${pattern}`);
this.settings.connection.enhancedLogging &&
this.log.silly(`${this.namespace} redis punsubscribe ${this.namespaceRedis}${pattern}`);
subClient.punsubscribe(this.namespaceRedis + pattern, err => {

@@ -945,3 +1123,3 @@ if (!err && subClient.ioBrokerSubscriptions[this.namespaceRedis + pattern] !== undefined) {

state._id = this.globalMessageId++;
if (this.globalMessageId >= 0xFFFFFFFF) {
if (this.globalMessageId >= 0xffffffff) {
this.globalMessageId = 0;

@@ -969,3 +1147,4 @@ }

}
this.settings.connection.enhancedLogging && this.log.silly(`${this.namespace} redis subscribeMessage ${this.namespaceMsg}${id}`);
this.settings.connection.enhancedLogging &&
this.log.silly(`${this.namespace} redis subscribeMessage ${this.namespaceMsg}${id}`);
try {

@@ -992,3 +1171,4 @@ await this.subSystem.psubscribe(this.namespaceMsg + id);

}
this.settings.connection.enhancedLogging && this.log.silly(`${this.namespace} redis unsubscribeMessage ${this.namespaceMsg}${id}`);
this.settings.connection.enhancedLogging &&
this.log.silly(`${this.namespace} redis unsubscribeMessage ${this.namespaceMsg}${id}`);
try {

@@ -1011,3 +1191,3 @@ await this.subSystem.punsubscribe(this.namespaceMsg + id);

log._id = this.globalLogId++;
if (this.globalLogId >= 0xFFFFFFFF) {
if (this.globalLogId >= 0xffffffff) {
this.globalLogId = 0;

@@ -1064,3 +1244,4 @@ }

this.settings.connection.enhancedLogging && this.log.silly(`${this.namespace} redis subscribeMessage ${this.namespaceLog}${id}`);
this.settings.connection.enhancedLogging &&
this.log.silly(`${this.namespace} redis subscribeMessage ${this.namespaceLog}${id}`);
try {

@@ -1084,3 +1265,4 @@ await this.subSystem.psubscribe(this.namespaceLog + id);

this.settings.connection.enhancedLogging && this.log.silly(`${this.namespace} redis unsubscribeMessage ${this.namespaceLog}${id}`);
this.settings.connection.enhancedLogging &&
this.log.silly(`${this.namespace} redis unsubscribeMessage ${this.namespaceLog}${id}`);
try {

@@ -1134,3 +1316,4 @@ await this.subSystem.punsubscribe(this.namespaceLog + id);

await this.client.setex(this.namespaceSession + id, expire, JSON.stringify(obj));
this.settings.connection.enhancedLogging && this.log.silly(`${this.namespace} redis setex`, id, expire, obj);
this.settings.connection.enhancedLogging &&
this.log.silly(`${this.namespace} redis setex`, id, expire, obj);
return tools.maybeCallback(callback);

@@ -1216,4 +1399,37 @@ } catch (e) {

}
/**
* Returns the protocol version from DB
*
* @returns {Promise<string>}
*/
getProtocolVersion() {
if (!this.client) {
throw new Error(tools.ERRORS.ERROR_DB_CLOSED);
}
return this.client.get(`${this.metaNamespace}states.protocolVersion`);
}
/**
* Sets the protocol version to the DB
* @param {number} version - protocol version
* @returns {Promise<void>}
*/
async setProtocolVersion(version) {
if (!this.client) {
throw new Error(tools.ERRORS.ERROR_DB_CLOSED);
}
version = version.toString();
// we can only set a protocol if we actually support it
if (this.supportedProtocolVersions.includes(version)) {
await this.client.set(`${this.metaNamespace}states.protocolVersion`, version);
await this.client.publish(`${this.metaNamespace}states.protocolVersion`, version);
} else {
throw new Error('Cannot set an unsupported protocol version on the current host');
}
}
}
module.exports = StateRedisClient;
{
"name": "@iobroker/db-states-redis",
"version": "4.0.0-alpha.3-20210903-1d3954b5",
"version": "4.0.0-alpha.30-20211220-ce617590",
"engines": {

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

"dependencies": {
"@iobroker/db-base": "4.0.0-alpha.3-20210903-1d3954b5",
"ioredis": "^4.27.6"
"@iobroker/db-base": "4.0.0-alpha.30-20211220-ce617590",
"ioredis": "^4.28.2"
},

@@ -33,3 +33,7 @@ "keywords": [

},
"gitHead": "a291fda216ac33d5b40e65c8a3b2c93aea62ab03"
"files": [
"lib/",
"index.js"
],
"gitHead": "fafabd20af76b3cae124318c8af3d3826d2979c3"
}
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