diff --git a/Changes.md b/Changes.md index e45d481..c994c6e 100644 --- a/Changes.md +++ b/Changes.md @@ -1,4 +1,8 @@ +### 1.0.11 - 2019-04-11 + +- create custom connection only after: all 3 conditions match + ### 1.0.10 - 2019-04-09 - merge ALL of [opts] into [server] config (fixes #18) diff --git a/index.js b/index.js index f2e8b72..c8f180c 100644 --- a/index.js +++ b/index.js @@ -88,17 +88,17 @@ exports.init_redis_plugin = function (next, server) { if (!server) server = { notes: {} }; const pidb = plugin.cfg.redis.db; - if (pidb !== undefined && pidb !== plugin.redisCfg.db) { - plugin.db = plugin.get_redis_client(plugin.cfg.redis, nextOnce); - return; + if (server.notes.redis) { // server-wide redis is available + // and the DB not specified or is the same as server-wide + if (pidb === undefined || pidb === plugin.redisCfg.db) { + server.loginfo(plugin, 'using server.notes.redis'); + plugin.db = server.notes.redis; + nextOnce(); + return; + } } - // use server-wide redis connection when DB not specified - if (server.notes.redis) { - server.loginfo(plugin, 'using server.notes.redis'); - plugin.db = server.notes.redis; - nextOnce(); - } + plugin.db = plugin.get_redis_client(plugin.cfg.redis, nextOnce); } exports.shutdown = function () { diff --git a/package.json b/package.json index 3d2960e..39cceaf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "haraka-plugin-redis", - "version": "1.0.10", + "version": "1.0.11", "description": "Redis plugin for Haraka & other plugins to inherit from", "main": "index.js", "directories": { diff --git a/test/redis.js b/test/redis.js index 1f32d1b..0875e74 100644 --- a/test/redis.js +++ b/test/redis.js @@ -19,7 +19,7 @@ function retry (options) { return undefined; } -exports.redis = { +exports.config = { setUp : _set_up_redis, 'loads' : function (test) { test.expect(1); @@ -70,6 +70,15 @@ exports.redis = { }); test.done(); }, +} + +exports.connects = { + setUp : _set_up_redis, + 'loads' : function (test) { + test.expect(1); + test.equal(this.plugin.name, 'index'); + test.done(); + }, 'connects' : function (test) { test.expect(1); const redis = this.plugin.get_redis_client({