Skip to content

Commit

Permalink
more redis promise updates
Browse files Browse the repository at this point in the history
  • Loading branch information
msimerson committed May 27, 2022
1 parent 84b42ce commit c7789f1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
23 changes: 12 additions & 11 deletions outbound/tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ class OutboundTLS {
if (!obtls.cfg.redis.disable_for_failed_hosts) return cb_ok();

const dbkey = `no_tls|${host}`;
obtls.db.get(dbkey, (err, dbr) => {
if (err) {
obtls.db.get(dbkey)
.then(dbr => {
dbr ? cb_nogo(dbr) : cb_ok();
})
.catch(err => {
obtls.logdebug(obtls, `Redis returned error: ${err}`);
return cb_ok();
}

return dbr ? cb_nogo(dbr) : cb_ok();
});
cb_ok();
})
}

mark_tls_nogo (host, cb) {
Expand All @@ -97,10 +97,11 @@ class OutboundTLS {

logger.lognotice(obtls, `TLS connection failed. Marking ${host} as non-TLS for ${expiry} seconds`);

obtls.db.setex(dbkey, expiry, (new Date()).toISOString(), (err, dbr) => {
if (err) logger.logerror(obtls, `Redis returned error: ${err}`);
cb();
});
obtls.db.setex(dbkey, expiry, (new Date()).toISOString())
.then(cb)
.catch(err => {
logger.logerror(obtls, `Redis returned error: ${err}`);
})
}
}

Expand Down
27 changes: 13 additions & 14 deletions plugins/dns_list_base.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,10 @@ exports.stats_incr_zone = function (err, zone, start) {

const rkey = `dns-list-stat:${zone}`;
const elapsed = new Date().getTime() - start;
redis_client.hincrby(rkey, 'TOTAL', 1);
redis_client.hIncrBy(rkey, 'TOTAL', 1);
const foo = (err) ? err.code : 'LISTED';
redis_client.hincrby(rkey, foo, 1);
redis_client.hget(rkey, 'AVG_RT', (err2, rt) => {
if (err2) return;
redis_client.hIncrBy(rkey, foo, 1);
redis_client.hGet(rkey, 'AVG_RT').then(rt => {
const avg = parseInt(rt) ? (parseInt(elapsed) + parseInt(rt))/2
: parseInt(elapsed);
redis_client.hset(rkey, 'AVG_RT', avg);
Expand All @@ -89,12 +88,14 @@ exports.init_redis = function () {
const port = parseInt(host_port[1], 10) || 6379;

redis_client = redis.createClient(port, host);
redis_client.on('error', err => {
plugin.logerror(`Redis error: ${err}`);
redis_client.quit();
redis_client = null; // should force a reconnect
// not sure if that's the right thing but better than nothing...
});
redis_client.connect().then(() => {
redis_client.on('error', err => {
plugin.logerror(`Redis error: ${err}`);
redis_client.quit();
redis_client = null; // should force a reconnect
// not sure if that's the right thing but better than nothing...
})
})
}

exports.multi = function (lookup, zones, cb) {
Expand All @@ -110,7 +111,7 @@ exports.multi = function (lookup, zones, cb) {
// Statistics: check hit overlap
for (let i=0; i < listed.length; i++) {
const foo = (listed[i] === zone) ? 'TOTAL' : listed[i];
redis_client.hincrby(`dns-list-overlap:${zone}`, foo, 1);
redis_client.hIncrBy(`dns-list-overlap:${zone}`, foo, 1);
}
}

Expand Down Expand Up @@ -194,9 +195,7 @@ exports.check_zones = function (interval) {

exports.shutdown = function () {
clearInterval(this._interval);
if (redis_client) {
redis_client.quit();
}
if (redis_client) redis_client.quit();
}

exports.disable_zone = function (zone, result) {
Expand Down

0 comments on commit c7789f1

Please sign in to comment.