Raw
1 import { Table, Prerequisites } from "docs-ui"
2
3 export const metadata = {
4 title: `Redis Event Module`,
5 }
6
7 # {metadata.title}
8
9 The Redis Event Module uses Redis to implement Medusa's pub/sub events system.
10
11 It's powered by [BullMQ](https://bullmq.io/) and `io-redis`. BullMQ is responsible for the message queue and worker, and `io-redis` is the underlying Redis client that BullMQ connects to for events storage.
12
13 In production, it's recommended to use this module.
14
15 <Note title="Using Cloud?">
16
17 Our Cloud offering automatically provisions a Redis instance and configures the Redis Event Module for you. Learn more in the [Redis](!cloud!/redis) Cloud documentation.
18
19 </Note>
20
21 ---
22
23 ## Register the Redis Event Module
24
25 <Prerequisites items={[
26 {
27 text: "Redis installed and Redis server running",
28 link: "https://redis.io/docs/getting-started/installation/"
29 }
30 ]} />
31
32 Add the module into the `modules` property of the exported object in `medusa-config.ts`:
33
34 export const highlights = [
35 ["11", "redisUrl", "The Redis connection URL."]
36 ]
37
38 ```ts title="medusa-config.ts"
39 import { Modules } from "@medusajs/framework/utils"
40
41 // ...
42
43 module.exports = defineConfig({
44 // ...
45 modules: [
46 {
47 resolve: "@medusajs/medusa/event-bus-redis",
48 options: {
49 redisUrl: process.env.EVENTS_REDIS_URL,
50 // suggested additional options for production use
51 jobOptions: {
52 removeOnComplete: {
53 // keep jobs for 1 hour or up to 1000 jobs
54 age: 3600,
55 count: 1000,
56 },
57 removeOnFail: {
58 // keep jobs for 1 hour or up to 1000 jobs
59 age: 3600,
60 count: 1000,
61 },
62 },
63 },
64 },
65 ],
66 })
67 ```
68
69 ### Environment Variables
70
71 Make sure to add the following environment variables:
72
73 ```bash
74 EVENTS_REDIS_URL=<YOUR_REDIS_URL>
75 ```
76
77 ### Redis Event Module Options
78
79 <Table>
80 <Table.Header>
81 <Table.Row>
82 <Table.HeaderCell>
83 Option
84 </Table.HeaderCell>
85 <Table.HeaderCell>
86 Description
87 </Table.HeaderCell>
88 <Table.HeaderCell>
89 Required
90 </Table.HeaderCell>
91 <Table.HeaderCell>
92 Default
93 </Table.HeaderCell>
94 </Table.Row>
95 </Table.Header>
96 <Table.Body>
97 <Table.Row>
98 <Table.Cell>
99
100 `redisUrl`
101
102 </Table.Cell>
103 <Table.Cell>
104
105 A string indicating the Redis connection URL.
106
107 </Table.Cell>
108 <Table.Cell>
109
110 Yes
111
112 </Table.Cell>
113 <Table.Cell>
114
115 \-
116
117 </Table.Cell>
118 </Table.Row>
119 <Table.Row>
120 <Table.Cell>
121
122 `redisOptions`
123
124 </Table.Cell>
125 <Table.Cell>
126
127 An object of Redis options. Refer to the [Redis API Reference](https://redis.github.io/ioredis/index.html#RedisOptions) for details on accepted properties.
128
129 </Table.Cell>
130 <Table.Cell>
131
132 No
133
134 </Table.Cell>
135 <Table.Cell>
136
137 \-
138
139 </Table.Cell>
140 </Table.Row>
141 <Table.Row>
142 <Table.Cell>
143
144 `queueName`
145
146 </Table.Cell>
147 <Table.Cell>
148
149 A string indicating BullMQ's queue name.
150
151 </Table.Cell>
152 <Table.Cell>
153
154 No
155
156 </Table.Cell>
157 <Table.Cell>
158
159 `events-queue`
160
161 </Table.Cell>
162 </Table.Row>
163 <Table.Row>
164 <Table.Cell>
165
166 `queueOptions`
167
168 </Table.Cell>
169 <Table.Cell>
170
171 An object of options to pass to the BullMQ constructor. Refer to [BullMQ's API reference](https://api.docs.bullmq.io/interfaces/v3.QueueOptions.html) for allowed properties.
172
173 </Table.Cell>
174 <Table.Cell>
175
176 No
177
178 </Table.Cell>
179 <Table.Cell>
180
181 \-
182
183 </Table.Cell>
184 </Table.Row>
185 <Table.Row>
186 <Table.Cell>
187
188 `workerOptions`
189
190 </Table.Cell>
191 <Table.Cell>
192
193 An object of options to pass to the BullMQ Worker constructor. Refer to [BullMQ's API reference](https://api.docs.bullmq.io/interfaces/v3.WorkerOptions.html) for allowed properties.
194
195 </Table.Cell>
196 <Table.Cell>
197
198 No
199
200 </Table.Cell>
201 <Table.Cell>
202
203 \-
204
205 </Table.Cell>
206 </Table.Row>
207 <Table.Row>
208 <Table.Cell>
209
210 `jobOptions`
211
212 </Table.Cell>
213 <Table.Cell>
214
215 An object of options to pass to jobs added to the BullMQ queue. Refer to [BullMQ's API reference](https://api.docs.bullmq.io/modules/v3.html#BulkJobOptions) for allowed properties.
216
217 </Table.Cell>
218 <Table.Cell>
219
220 No
221
222 </Table.Cell>
223 <Table.Cell>
224
225 \-
226
227 </Table.Cell>
228 </Table.Row>
229 </Table.Body>
230 </Table>
231
232 ## Test the Module
233
234 To test the module, start the Medusa application:
235
236 ```bash npm2yarn
237 npm run dev
238 ```
239
240 You'll see the following message in the terminal's logs:
241
242 ```bash noCopy noReport
243 Connection to Redis in module 'event-redis' established
244 ```