Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improved shared handle criteria #21

Merged
merged 2 commits into from
Apr 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
18 changes: 9 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
11 changes: 10 additions & 1 deletion test/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function retry (options) {
return undefined;
}

exports.redis = {
exports.config = {
setUp : _set_up_redis,
'loads' : function (test) {
test.expect(1);
Expand Down Expand Up @@ -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({
Expand Down