www/apps/resources/app/infrastructure-modules/cache/redis/page.mdx
import { Table, Prerequisites } from "docs-ui"
export const metadata = {
title: Redis Cache Module,
}
The Redis Cache Module uses Redis to cache data in your store. In production, it's recommended to use this module.
<Note title="Deprecation Notice">The Redis Cache Module is deprecated starting from Medusa v2.11.0. Use the Redis Caching Module Provider instead.
However, if you use OAuth-based authentication providers such as Google or GitHub login, keep the Redis Cache Module registered. The Auth Module uses the Cache Module to store OAuth state between the redirect and callback. Removing it without a Redis provider causes Medusa to use an in-memory fallback, which breaks OAuth flows in multi-instance or restarted deployments.
</Note><Prerequisites items={[ { text: "Redis installed and Redis server running", link: "https://redis.io/docs/getting-started/installation/" } ]} />
Add the module into the modules property of the exported object in medusa-config.ts:
export const highlights = [ ["7", "redisUrl", "The Redis connection URL."] ]
module.exports = defineConfig({
// ...
modules: [
{
resolve: "@medusajs/medusa/cache-redis",
options: {
redisUrl: process.env.CACHE_REDIS_URL,
},
},
],
})
Make sure to add the following environment variables:
CACHE_REDIS_URL=<YOUR_REDIS_URL>
`redisUrl`
</Table.Cell>
<Table.Cell>
A string indicating the Redis connection URL.
</Table.Cell>
<Table.Cell>
Yes
</Table.Cell>
<Table.Cell>
\-
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
`redisOptions`
</Table.Cell>
<Table.Cell>
An object of Redis options. Refer to the [Redis API Reference](https://redis.github.io/ioredis/index.html#RedisOptions) for details on accepted properties.
</Table.Cell>
<Table.Cell>
No
</Table.Cell>
<Table.Cell>
\-
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
`ttl`
</Table.Cell>
<Table.Cell>
The number of seconds an item can live in the cache before it’s removed.
</Table.Cell>
<Table.Cell>
No
</Table.Cell>
<Table.Cell>
`30` seconds
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
`namespace`
</Table.Cell>
<Table.Cell>
A string used to prefix all cached keys with `{namespace}:`.
</Table.Cell>
<Table.Cell>
No
</Table.Cell>
<Table.Cell>
`medusa`. So, all cached keys are prefixed with `medusa:`.
</Table.Cell>
</Table.Row>
</Table.Body>
</Table>To test the module, start the Medusa application:
npm run dev
You'll see the following message in the terminal's logs:
Connection to Redis in module 'cache-redis' established