Socket
Socket
Sign inDemoInstall

strapi-plugin-redis

Package Overview
Dependencies
17
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    strapi-plugin-redis

Plugin used to centralize management of Redis connections in Strapi


Version published
Maintainers
1
Install size
0.984 MB
Created

Readme

Source

Strapi Redis Plugin

Redis Connector Package for use in other plugins and packages.

Strapi Discord NPM Version Monthly download on NPM Vulnerabilities on Snyk

Table of Contents

🚦 Current Status

This package is currently under development and should be consider ALPHA in terms of state. I/We are currently accepting contributions and/or dedicated contributors to help develop and maintain this package.

For more information on contributing please see the contrib message below.

🛑 Foreword

This package's lead maintainer is an employee of Strapi however this package is not officially maintained by Strapi Solutions SAS nor Strapi, Inc. and is currently maintained in the free time of the lead maintainer.

Absolutely no part of this code should be considered covered under any agreement you have with Strapi proper including but not limited to any Enterprise Agreement you have with Strapi.

✨ Features

This plugin utilizes 1 core package:

  • ioredis - for all connection management

These are the primary features that are finished or currently being worked on:

  • Redis Single Node Support
  • Redis Replica + Sentinel Support
  • Redis Sharding Support (assumed working, no config samples)
  • Multiple connections/databases

🤔 Motivation

The purpose of this package is to have a universal Redis connector for all packages wanting to utilize a Redis database and/or for those wanting to develop custom functions and code within your Strapi project and would prefer a centralized Redis database for various purposes.

A few examples of where Redis could be used within a Strapi application:

  • LRU-based response cache for REST
  • Apollo server GraphQL cache
  • IP Rate-limiting using something like koa2-ratelimit
  • Distributed Redis locks for Strapi clusters (useful for clustered usage of cron tasks)
  • So much more

If you are currently using this package in your plugin and would like to be featured, please feel free to submit an issue to have your plugin added to the list below:

🖐 Requirements

Supported Strapi Versions:

Strapi VersionSupportedTested On
v3N/A
v4.0.xJuly 2022
v4.1.xJuly 2022
v4.2.xJuly 2022
v4.3.xDecember 2022
v4.4.xDecember 2022
v4.5.xDecember 2022
v4.6.xJanuary 2024
v4.7.xJanuary 2024
v4.8.xJanuary 2024
v4.9.xJanuary 2024
v4.10.xJanuary 2024
v4.11.xJanuary 2024
v4.12.xJanuary 2024
v4.13.xJanuary 2024
v4.14.xJanuary 2024
v4.15.xJanuary 2024
v4.16.xJanuary 2024
v4.17.xJanuary 2024
v4.19.xJanuary 2024

This plugin will not work with Strapi v3 projects as it utilizes APIs that don't exist in the v3!

⏳ Installation

Install the plugin in your Strapi project or your Strapi plugin.

# Using Yarn (Recommended)
yarn add strapi-plugin-redis

# Using npm
npm install strapi-plugin-redis --save

🔧 Configuration

WIP

Single Redis Node

// path ./config/plugins.js

module.exports = {
  redis: {
    config: {
      connections: {
        default: {
          connection: {
            host: '127.0.0.1',
            port: 6379,
            db: 0,
          },
          settings: {
            debug: false,
          },
        },
      },
    },
  },
};

Sentinel Replica (3 node)

// path ./config/plugins.js

module.exports = {
  redis: {
    config: {
      connections: {
        default: {
          connection: {
            sentinels: [
              { host: '192.168.1.101', port: 26379 },
              { host: '192.168.1.102', port: 26379 },
              { host: '192.168.1.103', port: 26379 },
            ],
            name: 'my-redis-replicaSet',
            db: 0,
          },
          settings: {
            debug: false,
          },
        },
      },
    },
  },
};

Using TLS with authentication

// path ./config/plugins.js
const { readFileSync } = require('fs');

module.exports = {
  redis: {
    config: {
      connections: {
        default: {
          connection: {
            // @see https://github.com/luin/ioredis/blob/master/API.md#new-redisport-host-options
            host: '127.0.0.1',
            port: 6379,
            db: 0,
            username: 'username',
            password: 'secret',
            // @see https://github.com/luin/ioredis#tls-options
            tls: {
              ca: readFileSync('cert.pem'),
            },
          },
          settings: {
            debug: false,
          },
        },
      },
    },
  },
};

🚚 Usage and API

This plugin directly mounts each Redis DB client and it's config on strapi.redis

Config

Access with: strapi.redis.config

The config key contains the entire plugin config including all ioredis instances configurations. These should not be modified after bootstrapping your Strapi application (aka while the server is running).

Connections

Access with: strapi.redis.connections

For each connection either a normal Redis client is created, or if the cluster setting is enabled and you have properly passed in an array of nodes (and optionally any cluster options) a Redis Cluster client.

Redis Client

Accessed with: strapi.redis.connections.default.client Note you can swap the default key with any other named database you have configured

From here you have full access to the ioredis API.

Contributing

I/We are actively looking for contributors, maintainers, and others to help shape this package. As this plugins sole purpose within the Strapi community is to be used by other developers and plugin maintainers to help ease the connection to Redis databases.

Instead of reinventing the wheel every time you need to connect to Redis, the hope is to centralize the connections in a single plugin that all plugins can piggy back on.

If interested please feel free to email the lead maintainer Derrick at: derrickmehaffy@gmail.com or ping DMehaffy on Discord.

Please Note: This package is maintained collectively by the strapi community organization. While there may be a lead maintainer, they are not the sole maintainer of this code and this code does not belong to the lead maintainer.

License

See the LICENSE file for licensing information.

FAQs

Last updated on 31 Jan 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc