Closed neural-loop closed 9 months ago
You need to install the `strapi-plugin-redis package I believe, can you give a copy of your package.json?
Thanks for responding - it's there in the first block of text under dependencies
"strapi-plugin-redis": "^1.0.1",
{
"name": "sitename",
"private": true,
"version": "0.1.0",
"description": "A Strapi application",
"scripts": {
"develop": "strapi develop",
"start": "strapi start",
"build": "strapi build",
"strapi": "strapi"
},
"dependencies": {
"@strapi/plugin-documentation": "4.10.7",
"@strapi/plugin-i18n": "4.10.7",
"@strapi/plugin-users-permissions": "4.10.7",
"@strapi/provider-email-nodemailer": "4.10.7",
"@strapi/strapi": "4.10.7",
"better-sqlite3": "8.4.0",
"pg": "8.8.0",
"pg-connection-string": "2.6.0",
"strapi-plugin-ezforms": "0.1.2",
"strapi-plugin-populate-deep": "2.0.0",
"strapi-plugin-redis": "^1.0.1",
"strapi-plugin-request-id": "1.1.0",
"strapi-plugin-rest-cache": "^4.2.7",
"strapi-plugin-sitemap": "^2.0.10",
"strapi-plugin-slugify": "^2.3.2",
"strapi-plugin-wysiwyg-react-md-editor": "4.3.0",
"strapi-provider-rest-cache-memory": "4.2.7",
"strapi-provider-rest-cache-redis": "^4.2.7"
},
"strapi": {
"uuid": ""
},
"engines": {
"node": ">=14.19.1 <=18.x.x",
"npm": ">= 8.0.0"
},
"license": "MIT"
}
I've had this error in all 4.x versions. Never could figure it out.
Is this plugin still maintained?
Is this plugin still maintained?
Yes it is in my free time but I've not been able to reproduce this issue
I think I know what causes the issue!
If you follow Strapi env variable and configuration conventions, you most likely created folders for your environemtns into the config folder. That is merged together with your default configs in the particular environment when you run strapi, but the order of each config might change!
The REST Cache plugin states that the redis plugin configuration MUST come before the REST Cache plugin config.
Now the error message what I had is not coming from this package, but from an intermediary package: strapi-provider-rest-cache-redis
For me, and hopefully for @neural-loop s issue the solution is to declare env dependant config into the base plugins.ts file like so:
export default ({ env }) => {
const redisConfig =
process.env.NODE_ENV !== 'production'
? {
enabled: false,
}
: {
config: {
connections: {
default: {
connection: {
host: '127.0.0.1',
port: 6379,
db: 0,
},
settings: {
debug: false,
},
},
},
},
};
const restCacheProviderOptions =
process.env.NODE_ENV !== 'production'
? {
name: 'memory',
options: {
max: 32767,
maxAge: 3600,
},
}
: {
name: 'redis',
options: {
max: 32767,
connection: 'default',
},
};
return {
redis: redisConfig,
'rest-cache': {
config: {
provider: restCacheProviderOptions,
strategy: {}
}
}
};
Not pretty, but gets the job done.
Not usually how I'd recommend doing that but that would work. If someone has a way to reproduce and show this plugin has a bug please let us know else for now I'm going to set this as resolved.
I haven't been able to figure this one out.
4|beta-api | [2023-06-20 17:55:48.221] debug: ⛔ Server wasn't able to start properly. 4|beta-api | [2023-06-20 17:55:48.225] error: Could not initialize REST Cache provider "redis". The package "strapi-plugin-redis" is required. 4|beta-api | Error: Could not initialize REST Cache provider "redis". The package "strapi-plugin-redis" is required.