strapi-hook-redis-connection

1.0.0 • Public • Published

strapi-hook-redis-connection

npm version npm downloads

This hook connects to Redis and exposes the connection as a global service through strapi. It uses the ioredis package

This hook is compatible with the stable version (3.x) of Strapi only.

Installation

$ yarn add strapi-hook-redis-connection
 
# or 
 
$ npm i strapi-hook-redis-connection --save

Configuration

To configure the hook edit or add the ./config/hook.js file in your Strapi app. The config object is passed to ioredis directly, consult ioredis docs for more info.

 
module.exports = ({ env }) => ({
    timeout: 2000,
    settings: {
        'redis-connection': {
            enabled: false,
            config: {
                host: env('REDIS_HOST', '127.0.0.1'), // Redis host
                port: env.int('REDIS_PORT', 6379), // Redis port
                password: env('REDIS_PASSWORD', '')
            }
        }
    },
});

Usage

Example to publish messages in a controller

module.exports = {
  index: async (ctx) => {
    const redis = strapi.services.redis;
 
    if (ctx.request.body.model && ctx.request.body.event) {
      redis.publish(ctx.request.body.model, ctx.request.body.event);
    }
 
    // Send 200 `ok`
    ctx.send({
      message: 'ok'
    });
  },
};

Resources

Readme

Keywords

Package Sidebar

Install

npm i strapi-hook-redis-connection

Weekly Downloads

22

Version

1.0.0

License

MIT

Unpacked Size

3.95 kB

Total Files

4

Last publish

Collaborators

  • cotyhamilton