First if statement will always return true due to usingConn[idx] always pointing to a number. This results in opening a new connection for each Redis-out, Redis-cmd, Redis-lua node but not closing them all properly upon their deletion.
function connect(config, force) {
var options = {};
var idx = config.id;
var config_env = _setEnv(config);
if (force !== undefined || usingConn[idx] === undefined ||
usingConn[idx] === 0 || usingConn[idx].connector === undefined) {
//usingConn[idx].connector is always undefined
if (config_env.pass !== "") {
options['password'] = config_env.pass;
}
if (config_env.dbase !== "") {
options['db'] = config_env.dbase;
}
var conn = redis.createClient(config_env.port, config_env.host, options);
conn.on('error', function(err) {
console.error('[redis]', err);
});
if (force !== undefined && force === true) {
return conn;
}
else {
connection[idx] = conn;
if (usingConn[idx] === undefined) {
usingConn[idx] = 1;
}
else {
usingConn[idx]++;
}
}
}
else {
usingConn[idx]++;
}
return connection[idx];
}
I've changed connection logic, now NodeRED reuses the connection on same flow by default, otherwise if you set block connection, node create a new connection.
First if statement will always return true due to usingConn[idx] always pointing to a number. This results in opening a new connection for each Redis-out, Redis-cmd, Redis-lua node but not closing them all properly upon their deletion.