haraka-plugin-redis
Advanced tools
Comparing version 1.0.12 to 1.0.13
### 1.0.13 - 2021-10-14 | ||
- switch CI from Travis to GitHub Actions | ||
- README: update formatting with GFM | ||
### 1.0.12 - 2020-03-16 | ||
@@ -8,2 +14,3 @@ | ||
### 1.0.11 - 2019-04-11 | ||
@@ -13,2 +20,3 @@ | ||
### 1.0.10 - 2019-04-09 | ||
@@ -15,0 +23,0 @@ |
20
index.js
'use strict'; | ||
/* global server */ | ||
const redis = require('redis'); | ||
const redis = require('redis'); | ||
@@ -14,5 +14,5 @@ exports.register = function () { | ||
// register these when 'redis' is declared in config/plugins | ||
plugin.register_hook('init_master', 'init_redis_shared'); | ||
plugin.register_hook('init_child', 'init_redis_shared'); | ||
// register when 'redis' is declared in config/plugins | ||
plugin.register_hook('init_master', 'init_redis_shared'); | ||
plugin.register_hook('init_child', 'init_redis_shared'); | ||
} | ||
@@ -144,3 +144,2 @@ | ||
exports.get_redis_client = function (opts, next) { | ||
const plugin = this; | ||
@@ -152,11 +151,11 @@ const client = redis.createClient(opts); | ||
.on('error', (err) => { | ||
plugin.logerror(err.message); | ||
this.logerror(err.message); | ||
next(err); | ||
}) | ||
.on('ready', () => { | ||
plugin.loginfo(`connected to ${urlStr}`); | ||
this.loginfo(`connected to ${urlStr}`); | ||
next(); | ||
}) | ||
.on('end', () => { | ||
plugin.loginfo(`Disconnected from ${urlStr}`); | ||
this.loginfo(`Disconnected from ${urlStr}`); | ||
}); | ||
@@ -236,9 +235,8 @@ | ||
exports.redis_unsubscribe = function (connection) { | ||
const plugin = this; | ||
if (!connection.notes.redis) { | ||
connection.logerror(plugin, `redis_unsubscribe called when no redis`) | ||
connection.logerror(this, `redis_unsubscribe called when no redis`) | ||
return; | ||
} | ||
connection.notes.redis.punsubscribe(plugin.get_redis_sub_channel(connection)); | ||
connection.notes.redis.punsubscribe(this.get_redis_sub_channel(connection)); | ||
} |
{ | ||
"name": "haraka-plugin-redis", | ||
"version": "1.0.12", | ||
"version": "1.0.13", | ||
"description": "Redis plugin for Haraka & other plugins to inherit from", | ||
@@ -10,6 +10,6 @@ "main": "index.js", | ||
"dependencies": { | ||
"redis": "^3.0.2" | ||
"redis": "^3.1.2" | ||
}, | ||
"devDependencies": { | ||
"eslint": "*", | ||
"eslint": ">=7", | ||
"eslint-plugin-haraka": "*", | ||
@@ -22,2 +22,3 @@ "haraka-test-fixtures": "*", | ||
"lintfix": "npx eslint --fix *.js test/*.js", | ||
"cover": "NODE_ENV=cov npx nyc --reporter=lcovonly npm run test", | ||
"test": "npx mocha --exit" | ||
@@ -24,0 +25,0 @@ }, |
@@ -5,4 +5,2 @@ # haraka-plugin-redis | ||
[![Code Climate][clim-img]][clim-url] | ||
[![Windows Build status][apv-img]][apv-url] | ||
[![Greenkeeper badge][gk-img]][gk-url] | ||
@@ -19,9 +17,13 @@ Connects to a redis instance. By default it stores a `redis` | ||
; host=127.0.0.1 | ||
; port=6379 | ||
```ini | ||
; host=127.0.0.1 | ||
; port=6379 | ||
``` | ||
### [pubsub] | ||
; host=127.0.0.1 | ||
; port=6379 | ||
```ini | ||
; host=127.0.0.1 | ||
; port=6379 | ||
``` | ||
@@ -32,5 +34,7 @@ Publish & Subscribe are DB agnostic and thus have no db setting. If host and port and not defined, they default to the same as [server] settings. | ||
; see https://www.npmjs.com/package/redis#options-object-properties | ||
; db=0 | ||
; password=battery-horse-staple | ||
```ini | ||
; see https://www.npmjs.com/package/redis#options-object-properties | ||
; db=0 | ||
; password=battery-horse-staple | ||
``` | ||
@@ -43,6 +47,8 @@ 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. | ||
if (server.notes.redis) { | ||
server.notes.redis.hgetall(...); | ||
// or any other redis command | ||
} | ||
```js | ||
if (server.notes.redis) { | ||
server.notes.redis.hgetall(...); | ||
// or any other redis command | ||
} | ||
``` | ||
@@ -53,15 +59,16 @@ ## Publish/Subscribe Usage | ||
exports.results_init = function (next, connection) { | ||
var plugin = this; | ||
plugin.redis_subscribe(connection, function () { | ||
connection.notes.redis.on('pmessage', function (pattern, channel, message) { | ||
plugin.do_something_with_message(message, ...); | ||
}); | ||
next(); | ||
}); | ||
} | ||
// be nice to redis and disconnect | ||
exports.hook_disconnect = function (next, connection) { | ||
this.redis_unsubscribe(connection); | ||
} | ||
```js | ||
exports.results_init = function (next, connection) { | ||
this.redis_subscribe(connection, () => { | ||
connection.notes.redis.on('pmessage', (pattern, channel, message) => { | ||
this.do_something_with_message(message, ...) | ||
}) | ||
next() | ||
}) | ||
} | ||
// be nice to redis and disconnect | ||
exports.hook_disconnect = function (next, connection) { | ||
this.redis_unsubscribe(connection) | ||
} | ||
``` | ||
@@ -73,22 +80,26 @@ ## Custom Usage | ||
exports.register = function () { | ||
const plugin = this; | ||
plugin.inherits('redis'); | ||
```js | ||
exports.register = function () { | ||
const plugin = this; | ||
plugin.inherits('redis'); | ||
plugin.cfg = plugin.config.get('my-plugin.ini'); | ||
plugin.cfg = plugin.config.get('my-plugin.ini'); | ||
// populate plugin.cfg.redis with defaults from redis.ini | ||
plugin.merge_redis_ini(); | ||
// populate plugin.cfg.redis with defaults from redis.ini | ||
plugin.merge_redis_ini(); | ||
// cluster aware redis connection(s) | ||
plugin.register_hook('init_master', 'init_redis_plugin'); | ||
plugin.register_hook('init_child', 'init_redis_plugin'); | ||
} | ||
// cluster aware redis connection(s) | ||
plugin.register_hook('init_master', 'init_redis_plugin'); | ||
plugin.register_hook('init_child', 'init_redis_plugin'); | ||
} | ||
``` | ||
When a db ID is specified in the [redis] section of a redis inheriting plugin, log messages like these will be emitted when Haraka starts: | ||
[INFO] [-] [redis] connected to redis://172.16.15.16:6379 v3.2.6 | ||
[INFO] [-] [limit] connected to redis://172.16.15.16:6379/1 v3.2.6 | ||
[INFO] [-] [karma] connected to redis://172.16.15.16:6379/2 v3.2.6 | ||
[INFO] [-] [known-senders] connected to redis://172.16.15.16:6379/3 v3.2.6 | ||
```` | ||
[INFO] [-] [redis] connected to redis://172.16.15.16:6379 v3.2.6 | ||
[INFO] [-] [limit] connected to redis://172.16.15.16:6379/1 v3.2.6 | ||
[INFO] [-] [karma] connected to redis://172.16.15.16:6379/2 v3.2.6 | ||
[INFO] [-] [known-senders] connected to redis://172.16.15.16:6379/3 v3.2.6 | ||
```` | ||
@@ -100,9 +111,5 @@ Notice the database ID numbers appended to each plugins redis connection | ||
[ci-img]: https://travis-ci.org/haraka/haraka-plugin-redis.svg | ||
[ci-url]: https://travis-ci.org/haraka/haraka-plugin-redis | ||
[ci-img]: https://github.com/haraka/haraka-plugin-redis/workflows/Tests/badge.svg | ||
[ci-url]: https://github.com/haraka/haraka-plugin-redis/actions?query=workflow%3ATests | ||
[clim-img]: https://codeclimate.com/github/haraka/haraka-plugin-redis/badges/gpa.svg | ||
[clim-url]: https://codeclimate.com/github/haraka/haraka-plugin-redis | ||
[apv-img]: https://ci.appveyor.com/api/projects/status/fxk78f25n61nq3lx?svg=true | ||
[apv-url]: https://ci.appveyor.com/project/msimerson/haraka-plugin-redis | ||
[gk-img]: https://badges.greenkeeper.io/haraka/haraka-plugin-redis.svg | ||
[gk-url]: https://greenkeeper.io/ |
109
17050
9
290
Updatedredis@^3.1.2