Redis Cache Module

The Redis Cache Module uses Redis to cache data in your store. In production, it's recommended to use this module.

Deprecation Notice: The Redis Cache Module is deprecated starting from Medusa v2.11.0. Use the Redis Caching Module Provider instead.

Register the Redis Cache Module#

Add the module into the modules property of the exported object in medusa-config.ts:

medusa-config.ts
1module.exports = defineConfig({2  // ...3  modules: [4    {5      resolve: "@medusajs/medusa/cache-redis",6      options: { 7        redisUrl: process.env.CACHE_REDIS_URL,8      },9    },10  ],11})

Environment Variables#

Make sure to add the following environment variables:

Terminal
CACHE_REDIS_URL=<YOUR_REDIS_URL>

Redis Cache Module Options#

OptionDescriptionRequiredDefault

redisUrl

A string indicating the Redis connection URL.

Yes

-

redisOptions

An object of Redis options. Refer to the Redis API Reference for details on accepted properties.

No

-

ttl

The number of seconds an item can live in the cache before it’s removed.

No

30 seconds

namespace

A string used to prefix all cached keys with {namespace}:.

No

medusa. So, all cached keys are prefixed with medusa:.


Test the Module#

To test the module, start the Medusa application:

You'll see the following message in the terminal's logs:

Terminal
Connection to Redis in module 'cache-redis' established
Was this page helpful?
Ask Anything
Ask any questions about Medusa. Get help with your development.
You can also use the Medusa MCP server in Cursor, VSCode, etc...
FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break