1 import { Table, Prerequisites } from "docs-ui"
2
3 export const metadata = {
4 title: `Redis Cache Module`,
5 }
6
7 # {metadata.title}
8
9 The Redis Cache Module uses Redis to cache data in your store. In production, it's recommended to use this module.
10
11 <Note title="Deprecation Notice">
12
13 The Redis Cache Module is deprecated starting from [Medusa v2.11.0](https://github.com/medusajs/medusa/releases/tag/v2.11.0). Use the [Redis Caching Module Provider](../../caching/providers/redis/page.mdx) instead.
14
15 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.
16
17 </Note>
18
19 ---
20
21 ## Register the Redis Cache Module
22
23 <Prerequisites items={[
24 {
25 text: "Redis installed and Redis server running",
26 link: "https://redis.io/docs/getting-started/installation/"
27 }
28 ]} />
29
30 Add the module into the `modules` property of the exported object in `medusa-config.ts`:
31
32 export const highlights = [
33 ["7", "redisUrl", "The Redis connection URL."]
34 ]
35
36 ```ts title="medusa-config.ts" highlights={highlights}
37 module.exports = defineConfig({
38 // ...
39 modules: [
40 {
41 resolve: "@medusajs/medusa/cache-redis",
42 options: {
43 redisUrl: process.env.CACHE_REDIS_URL,
44 },
45 },
46 ],
47 })
48 ```
49
50 ### Environment Variables
51
52 Make sure to add the following environment variables:
53
54 ```bash
55 CACHE_REDIS_URL=<YOUR_REDIS_URL>
56 ```
57
58 ### Redis Cache Module Options
59
60 <Table>
61 <Table.Header>
62 <Table.Row>
63 <Table.HeaderCell>
64 Option
65 </Table.HeaderCell>
66 <Table.HeaderCell>
67 Description
68 </Table.HeaderCell>
69 <Table.HeaderCell>
70 Required
71 </Table.HeaderCell>
72 <Table.HeaderCell>
73 Default
74 </Table.HeaderCell>
75 </Table.Row>
76 </Table.Header>
77 <Table.Body>
78 <Table.Row>
79 <Table.Cell>
80
81 `redisUrl`
82
83 </Table.Cell>
84 <Table.Cell>
85
86 A string indicating the Redis connection URL.
87
88 </Table.Cell>
89 <Table.Cell>
90
91 Yes
92
93 </Table.Cell>
94 <Table.Cell>
95
96 \-
97
98 </Table.Cell>
99 </Table.Row>
100 <Table.Row>
101 <Table.Cell>
102
103 `redisOptions`
104
105 </Table.Cell>
106 <Table.Cell>
107
108 An object of Redis options. Refer to the [Redis API Reference](https://redis.github.io/ioredis/index.html#RedisOptions) for details on accepted properties.
109
110 </Table.Cell>
111 <Table.Cell>
112
113 No
114
115 </Table.Cell>
116 <Table.Cell>
117
118 \-
119
120 </Table.Cell>
121 </Table.Row>
122 <Table.Row>
123 <Table.Cell>
124
125 `ttl`
126
127 </Table.Cell>
128 <Table.Cell>
129
130 The number of seconds an item can live in the cache before it’s removed.
131
132 </Table.Cell>
133 <Table.Cell>
134
135 No
136
137 </Table.Cell>
138 <Table.Cell>
139
140 `30` seconds
141
142 </Table.Cell>
143 </Table.Row>
144 <Table.Row>
145 <Table.Cell>
146
147 `namespace`
148
149 </Table.Cell>
150 <Table.Cell>
151
152 A string used to prefix all cached keys with `{namespace}:`.
153
154 </Table.Cell>
155 <Table.Cell>
156
157 No
158
159 </Table.Cell>
160 <Table.Cell>
161
162 `medusa`. So, all cached keys are prefixed with `medusa:`.
163
164 </Table.Cell>
165 </Table.Row>
166 </Table.Body>
167 </Table>
168
169 ---
170
171 ## Test the Module
172
173 To test the module, start the Medusa application:
174
175 ```bash npm2yarn
176 npm run dev
177 ```
178
179 You'll see the following message in the terminal's logs:
180
181 ```bash noCopy noReport
182 Connection to Redis in module 'cache-redis' established
183 ```