Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

haraka-plugin-redis

Package Overview
Dependencies
Maintainers
3
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

haraka-plugin-redis - npm Package Compare versions

Comparing version 1.0.9 to 1.0.10

config/redis.ini

28

Changes.md
# 1.0.9 - 2019-02-19
### 1.0.10 - 2019-04-09
- merge ALL of [opts] into [server] config (fixes #18)
- merge all of [opts] into [pubsub] config
- include an empty config/redis.ini
- add defaultOpts once, vs defaults in two places
### 1.0.9 - 2019-02-19
- bump redis version to 2.8.0

@@ -9,25 +17,31 @@ - emit error message if redis connection fails

# 1.0.8 - 2018-01-03
### 1.0.8 - 2018-01-03
- upon punsubscribe, `quit()` (disconnect) redis client
# 1.0.7 - 2017-07-31
### 1.0.7 - 2017-07-31
- apply config [opts] to pubsub settings #7
# 1.0.6 - 2017-06-16
### 1.0.6 - 2017-06-16
- eslint 4 compat
# 1.0.5 - 2017-06-09
### 1.0.5 - 2017-06-09
- disconnect per-connection redis client upon punsubscribe
# 1.0.4 - 2017-02-06
### 1.0.4 - 2017-02-06
- remove retry_strategy, redis client now does The Right Thing w/o it
# 1.0.3 - 2017-02-06
### 1.0.3 - 2017-02-06
- don't break when no [redis] config exists

@@ -19,5 +19,9 @@ 'use strict';

const defaultOpts = { host: '127.0.0.1', port: '6379' };
exports.load_redis_ini = function () {
const plugin = this;
// store redis cfg at redisCfg, to avoid conflicting with plugins that
// inherit this plugin and have *their* config at plugin.cfg
plugin.redisCfg = plugin.config.get('redis.ini', function () {

@@ -27,19 +31,7 @@ plugin.load_redis_ini();

if (!plugin.redisCfg.server) plugin.redisCfg.server = {};
const s = plugin.redisCfg.server;
if (s.ip && !s.host) s.host = s.ip;
if (!s.host) s.host = '127.0.0.1';
if (!s.port) s.port = '6379';
const rc = plugin.redisCfg;
plugin.redisCfg.server = Object.assign({}, defaultOpts, rc.opts, rc.server);
if (rc.server.ip && !rc.server.host) rc.server.host = rc.server.ip; // backwards compat
if (!plugin.redisCfg.pubsub) {
plugin.redisCfg.pubsub = JSON.parse(JSON.stringify(s));
}
const ps = plugin.redisCfg.pubsub;
if (!ps.host) ps.host = s.host;
if (!ps.port) ps.port = s.port;
if (plugin.redisCfg.opts === undefined) plugin.redisCfg.opts = {};
Object.keys(plugin.redisCfg.opts).forEach(opt => {
if (ps[opt] === undefined) ps[opt] = plugin.redisCfg.opts[opt];
});
plugin.redisCfg.pubsub = Object.assign({}, defaultOpts, rc.opts, rc.server, rc.pubsub);
}

@@ -50,14 +42,7 @@

if (!plugin.cfg) plugin.cfg = {}; // no <plugin>.ini loaded?
if (!plugin.cfg) plugin.cfg = {}; // no <plugin>.ini loaded?
if (!plugin.cfg.redis) plugin.cfg.redis = {}; // no [redis] in <plugin>.ini file
if (!plugin.redisCfg) plugin.load_redis_ini();
if (!plugin.cfg.redis) { // no [redis] in <plugin>.ini file
plugin.cfg.redis = {};
}
if (!plugin.redisCfg) plugin.load_redis_ini();
['host', 'port', 'db'].forEach((k) => {
if (plugin.cfg.redis[k] !== undefined) return; // already set
plugin.cfg.redis[k] = plugin.redisCfg.server[k];
});
plugin.cfg.redis = Object.assign({}, plugin.redisCfg.server, plugin.cfg.redis);
}

@@ -78,16 +63,13 @@

// specificy a db ID.
if (server.notes.redis) {
server.notes.redis.ping((err, res) => {
if (err) return nextOnce(err);
if (!server.notes.redis) {
server.notes.redis = plugin.get_redis_client(plugin.redisCfg.server, nextOnce);
return
}
plugin.loginfo('already connected');
nextOnce(); // connection is good
});
}
else {
const opts = JSON.parse(JSON.stringify(plugin.redisCfg.opts));
opts.host = plugin.redisCfg.server.host;
opts.port = plugin.redisCfg.server.port;
server.notes.redis = plugin.get_redis_client(opts, nextOnce);
}
server.notes.redis.ping((err, res) => {
if (err) return nextOnce(err);
plugin.loginfo('already connected');
nextOnce(); // connection is good
});
}

@@ -112,12 +94,14 @@

// use server-wide redis connection when using default DB id
if (!plugin.cfg.redis.db) {
if (server.notes.redis) {
server.loginfo(plugin, 'using server.notes.redis');
plugin.db = server.notes.redis;
return nextOnce();
}
const pidb = plugin.cfg.redis.db;
if (pidb !== undefined && pidb !== plugin.redisCfg.db) {
plugin.db = plugin.get_redis_client(plugin.cfg.redis, nextOnce);
return;
}
plugin.db = plugin.get_redis_client(plugin.cfg.redis, nextOnce);
// 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();
}
}

@@ -158,3 +142,3 @@

if (client && client.server_info && client.server_info.redis_version) {
msg += ` v${client.server_info.redis_version}`;
msg += `\tv${client.server_info.redis_version}`;
}

@@ -167,5 +151,2 @@ return msg;

if (!opts.host) opts.host = 'localhost'
if (!opts.port) opts.port = '6379'
const client = redis.createClient(opts);

@@ -180,3 +161,3 @@ const urlStr = getUriStr(client, opts);

.on('ready', () => {
plugin.loginfo(plugin, `connected to ${urlStr}`);
plugin.loginfo(`connected to ${urlStr}`);
next();

@@ -183,0 +164,0 @@ })

{
"name": "haraka-plugin-redis",
"version": "1.0.9",
"version": "1.0.10",
"description": "Redis plugin for Haraka & other plugins to inherit from",

@@ -21,3 +21,3 @@ "main": "index.js",

"lintfix": "./node_modules/.bin/eslint --fix *.js test/*.js",
"test": "./run_tests"
"test": "node run_tests"
},

@@ -24,0 +24,0 @@ "repository": {

@@ -20,3 +20,2 @@ # haraka-plugin-redis

; port=6379
; db=0

@@ -32,4 +31,7 @@ ### [pubsub]

; see https://www.npmjs.com/package/redis#overloading
; see https://www.npmjs.com/package/redis#options-object-properties
; db=0
; password=battery-horse-staple
Options specified in `redis.ini[opts]` are applied to the server config, the pubsub config, AND the configurations of any plugins that inherit this plugin. This is ideal if the redis server requires a password. Specify it once in [opts]. If other redis connections need a different value (such as a unique DB), they must specify it. For plugins, all options are stored in the plugins `[redis]` section of its config file.

@@ -66,6 +68,6 @@ ## Usage (shared redis)

This variation lets your plugin establish its own Redis connection,
optionally with a redis db ID.
optionally with a redis db ID. All redis config options must be listed in your plugins config file in the [redis] section.
exports.register = function () {
var plugin = this;
const plugin = this;
plugin.inherits('redis');

@@ -94,9 +96,5 @@

`[![Coverage Status][cov-img]][cov-url]` nyet
[ci-img]: https://travis-ci.org/haraka/haraka-plugin-redis.svg
[ci-url]: https://travis-ci.org/haraka/haraka-plugin-redis
[cov-img]: https://codecov.io/github/haraka/haraka-plugin-redis/coverage.svg
[cov-url]: https://codecov.io/github/haraka/haraka-plugin-redis?branch=master
[clim-img]: https://codeclimate.com/github/haraka/haraka-plugin-redis/badges/gpa.svg

@@ -103,0 +101,0 @@ [clim-url]: https://codeclimate.com/github/haraka/haraka-plugin-redis

'use strict';
const fixtures = require('haraka-test-fixtures');
const path = require('path');
const fixtures = require('haraka-test-fixtures');
function _set_up_redis (done) {

@@ -33,2 +35,40 @@

},
'merges [opts] into server config': function (test) {
this.plugin.config = this.plugin.config.module_config(path.resolve('test'));
this.plugin.load_redis_ini();
test.expect(1);
test.deepEqual(this.plugin.redisCfg, {
main: {},
pubsub: {
host: '127.0.0.1',
port: '6379',
db: 5,
password: 'dontUseThisOne'
},
opts: { db: 5, password: 'dontUseThisOne' },
server: {
host: '127.0.0.1',
port: '6379',
db: 5,
password: 'dontUseThisOne'
}
});
test.done();
},
'merges redis.ini [opts] into plugin config': function (test) {
this.plugin.config = this.plugin.config.module_config(path.resolve('test'));
this.plugin.load_redis_ini();
this.plugin.cfg = {};
this.plugin.merge_redis_ini();
test.expect(1);
test.deepEqual(this.plugin.cfg, {
redis: {
host: '127.0.0.1',
port: '6379',
db: 5,
password: 'dontUseThisOne'
}
});
test.done();
},
'connects' : function (test) {

@@ -50,3 +90,3 @@ test.expect(1);

this.plugin.merge_redis_ini();
test.deepEqual(this.plugin.cfg.redis, { host: '127.0.0.1', port: '6379', db: undefined });
test.deepEqual(this.plugin.cfg.redis, { host: '127.0.0.1', port: '6379' });
test.done();

@@ -53,0 +93,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc