npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

strapi-plugin-redis

v1.1.0

Published

Plugin used to centralize management of Redis connections in Strapi

Downloads

13,939

Readme

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:

  • [x] Redis Single Node Support
  • [x] Redis Replica + Sentinel Support
  • [ ] Redis Sharding Support (assumed working, no config samples)
  • [x] 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 Version | Supported | Tested On | | -------------- | --------- | ------------- | | v3 | ❌ | N/A | | v4.0.x | ✅ | July 2022 | | v4.1.x | ✅ | July 2022 | | v4.2.x | ✅ | July 2022 | | v4.3.x | ✅ | December 2022 | | v4.4.x | ✅ | December 2022 | | v4.5.x | ✅ | December 2022 | | v4.6.x | ✅ | January 2024 | | v4.7.x | ✅ | January 2024 | | v4.8.x | ✅ | January 2024 | | v4.9.x | ✅ | January 2024 | | v4.10.x | ✅ | January 2024 | | v4.11.x | ✅ | January 2024 | | v4.12.x | ✅ | January 2024 | | v4.13.x | ✅ | January 2024 | | v4.14.x | ✅ | January 2024 | | v4.15.x | ✅ | January 2024 | | v4.16.x | ✅ | January 2024 | | v4.17.x | ✅ | January 2024 | | v4.19.x | ✅ | January 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: [email protected] 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.