Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

haraka-plugin-redis

haraka13.6kMIT2.0.10

Redis plugin for Haraka & other plugins to inherit from

haraka, haraka-plugin, mail, smtp, redis

readme

haraka-plugin-redis

Build Status Code Climate

Connects to a redis instance. By default it stores a redis connection handle at server.notes.redis. See below to get a custom DB handle attached to another database.

Config

The redis.ini file has the following sections (defaults shown):

[server]

; host=127.0.0.1
; port=6379

[pubsub]

; host=127.0.0.1
; port=6379

Publish & Subscribe are DB agnostic and thus have no db setting. If host and port and not defined, they default to the same as [socket] settings.

[opts]

; see https://github.com/redis/node-redis/blob/HEAD/docs/client-configuration.md
; database=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.

Usage (shared redis)

Use redis in your plugin like so:

if (server.notes.redis) {
    server.notes.redis.hGetAll(...);
        // or any other redis command
}

Publish/Subscribe Usage

In your plugin:

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)
}

Custom Usage

This variation lets your plugin establish its own Redis connection, 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 () {
  this.inherits('redis')

  this.cfg = this.config.get('my-plugin.ini')

  // populate plugin.cfg.redis with defaults from redis.ini
  this.merge_redis_ini()

  // cluster aware redis connection(s)
  this.register_hook('init_master', 'init_redis_plugin')
  this.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

Notice the database ID numbers appended to each plugins redis connection message.

changelog

Changelog

The format is based on Keep a Changelog.

Unreleased

2.0.10 - 2025-06-02

  • dep(redis): upgrade to 5.1.1 (was 4.6.0)

[2.0.9] - 2025-01-26

  • dep(eslint): upgrade to v9

2.0.8 - 2024-11-08

  • fix no client QUIT on shutdown when it is not connected #47
  • fix missing error handlers on pi-watch and pi-karma redis clients #46

2.0.7 - 2024-04-21

  • populate [files] in package.json. Delete .npmignore.
  • lint: remove duplicate / stale rules from .eslintrc
  • ci: update to shared GHA workflows
  • doc(CONTRIBUTORS): added
  • doc: Changes -> CHANGELOG
  • prettier

2.0.6 - 2023-12-12

  • doc(README): '[socket]' is now '[server]' (#39)
  • chore(ci): add .release, updated dot files

2.0.5 - 2022-05-26

  • fix: backwards compatibility with legacy plugin config files
  • fix: rename p* methods -> * (required in redis v4)
  • fix: add await client.connect() as is now required, fixes #32
  • fix: make redis_ping async
  • dep(redis): bump 4.0 -> 4.1
  • chore(ci): updated syntax
  • chore(ci): added codeql config
  • test: added tests for init_redis_plugin

2.0.0 - 2022-03-29

  • dep(redis): bump major version 3 -> 4
  • breaking API change: replaced callbacks with promises
  • config.ini
    • opts.db -> opts.database (to match upstream)

1.0.13 - 2021-10-14

  • chore(ci): switch CI from Travis to GitHub Actions
  • doc(README): update formatting with GFM

1.0.12 - 2020-03-16

  • chore(ci): replace nodeunit with mocha
  • dep(redis): update lib to v3
  • appveyor: test on node 10

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)
  • 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
  • emit error message if redis connection fails
  • add 3s timeout for subscribe connects: minimize connections stalls
  • add es6 template literals

1.0.8 - 2018-01-03

  • upon punsubscribe, quit() (disconnect) redis client

1.0.7 - 2017-07-31

  • apply config [opts] to pubsub settings #7

1.0.6 - 2017-06-16

  • eslint 4 compat

1.0.5 - 2017-06-09

  • disconnect per-connection redis client upon punsubscribe

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

  • don't break when no [redis] config exists