node-red-contrib-redis-variable 1.3.0 → 1.3.1
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/package.json +1 -1
- package/redis-variable-config.js +64 -0
- package/redis-variable.js +12 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-redis-variable",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "A comprehensive Node-RED node for Redis operations with universal payload-based configuration, automatic JSON handling, SSL/TLS support, and advanced pattern matching with pagination",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node-red",
|
package/redis-variable-config.js
CHANGED
|
@@ -157,6 +157,51 @@ module.exports = function (RED) {
|
|
|
157
157
|
}
|
|
158
158
|
};
|
|
159
159
|
|
|
160
|
+
// Check if configuration exists in context
|
|
161
|
+
this.hasValidConfiguration = function(msg, executingNode) {
|
|
162
|
+
try {
|
|
163
|
+
// If using string configuration for host and port, it's always valid
|
|
164
|
+
if (this.hostType === 'str' && this.portType === 'str') {
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// For context-based configuration, check if the required values exist
|
|
169
|
+
let hasHost = false;
|
|
170
|
+
let hasPort = false;
|
|
171
|
+
|
|
172
|
+
// Check host configuration
|
|
173
|
+
if (this.hostType === 'str') {
|
|
174
|
+
hasHost = !!(this.host);
|
|
175
|
+
} else {
|
|
176
|
+
const contextHost = this.parseCredentialValue(this.hostContext, this.hostType, msg, executingNode);
|
|
177
|
+
hasHost = !!(contextHost);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Check port configuration
|
|
181
|
+
if (this.portType === 'str') {
|
|
182
|
+
hasPort = !!(this.port);
|
|
183
|
+
} else {
|
|
184
|
+
const contextPort = this.parseCredentialValue(this.portContext, this.portType, msg, executingNode);
|
|
185
|
+
hasPort = !!(contextPort);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// We need at least host and port to have a valid configuration
|
|
189
|
+
const result = hasHost && hasPort;
|
|
190
|
+
|
|
191
|
+
if (executingNode && process.env.NODE_RED_DEBUG) {
|
|
192
|
+
executingNode.log(`Configuration check - hasHost: ${hasHost}, hasPort: ${hasPort}, result: ${result}`);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return result;
|
|
196
|
+
|
|
197
|
+
} catch (error) {
|
|
198
|
+
if (executingNode) {
|
|
199
|
+
executingNode.error(`Error checking configuration: ${error.message}`);
|
|
200
|
+
}
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
|
|
160
205
|
// Get Redis connection options
|
|
161
206
|
this.getConnectionOptions = function(msg, executingNode) {
|
|
162
207
|
try {
|
|
@@ -301,6 +346,25 @@ module.exports = function (RED) {
|
|
|
301
346
|
return connections[id];
|
|
302
347
|
}
|
|
303
348
|
|
|
349
|
+
// Check if configuration is available before attempting connection
|
|
350
|
+
if (!this.hasValidConfiguration(msg, executingNode)) {
|
|
351
|
+
if (executingNode) {
|
|
352
|
+
// Only warn once per node to avoid spam
|
|
353
|
+
if (!executingNode._configWarningShown) {
|
|
354
|
+
executingNode.warn("Redis configuration not available in context. Skipping connection attempt.");
|
|
355
|
+
executingNode._configWarningShown = true;
|
|
356
|
+
|
|
357
|
+
// Reset warning flag after 30 seconds
|
|
358
|
+
setTimeout(() => {
|
|
359
|
+
if (executingNode) {
|
|
360
|
+
executingNode._configWarningShown = false;
|
|
361
|
+
}
|
|
362
|
+
}, 30000);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
return null;
|
|
366
|
+
}
|
|
367
|
+
|
|
304
368
|
const options = this.getConnectionOptions(msg, executingNode);
|
|
305
369
|
|
|
306
370
|
// Add connection limits to prevent infinite retry loops
|
package/redis-variable.js
CHANGED
|
@@ -280,7 +280,12 @@ module.exports = function (RED) {
|
|
|
280
280
|
if (!client) {
|
|
281
281
|
client = redisConfig.getClient(msg, node, node.id);
|
|
282
282
|
if (!client) {
|
|
283
|
-
|
|
283
|
+
node.warn("Redis configuration not available. Operation skipped.");
|
|
284
|
+
node.status({ fill: "yellow", shape: "ring", text: "no config" });
|
|
285
|
+
msg.payload = { error: "Redis configuration not available" };
|
|
286
|
+
send(msg);
|
|
287
|
+
done();
|
|
288
|
+
return;
|
|
284
289
|
}
|
|
285
290
|
}
|
|
286
291
|
|
|
@@ -296,7 +301,12 @@ module.exports = function (RED) {
|
|
|
296
301
|
client = null;
|
|
297
302
|
client = redisConfig.getClient(msg, node, node.id);
|
|
298
303
|
if (!client) {
|
|
299
|
-
|
|
304
|
+
node.warn("Redis configuration not available during reconnection. Operation skipped.");
|
|
305
|
+
node.status({ fill: "yellow", shape: "ring", text: "no config" });
|
|
306
|
+
msg.payload = { error: "Redis configuration not available" };
|
|
307
|
+
send(msg);
|
|
308
|
+
done();
|
|
309
|
+
return;
|
|
300
310
|
}
|
|
301
311
|
} catch (reconnectError) {
|
|
302
312
|
throw new Error(`Failed to reconnect: ${reconnectError.message}`);
|