www/apps/resources/app/infrastructure-modules/event/redis/page.mdx
import { Table, Prerequisites } from "docs-ui"
export const metadata = {
title: Redis Event Module,
}
The Redis Event Module uses Redis to implement Medusa's pub/sub events system.
It's powered by BullMQ 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.
In production, it's recommended to use this module.
<Note title="Using Cloud?">Our Cloud offering automatically provisions a Redis instance and configures the Redis Event Module for you. Learn more in the Redis Cloud documentation.
</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 = [ ["11", "redisUrl", "The Redis connection URL."] ]
import { Modules } from "@medusajs/framework/utils"
// ...
module.exports = defineConfig({
// ...
modules: [
{
resolve: "@medusajs/medusa/event-bus-redis",
options: {
redisUrl: process.env.EVENTS_REDIS_URL,
// suggested additional options for production use
jobOptions: {
removeOnComplete: {
// keep jobs for 1 hour or up to 1000 jobs
age: 3600,
count: 1000,
},
removeOnFail: {
// keep jobs for 1 hour or up to 1000 jobs
age: 3600,
count: 1000,
},
},
},
},
],
})
Make sure to add the following environment variables:
EVENTS_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>
`queueName`
</Table.Cell>
<Table.Cell>
A string indicating BullMQ's queue name.
</Table.Cell>
<Table.Cell>
No
</Table.Cell>
<Table.Cell>
`events-queue`
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
`queueOptions`
</Table.Cell>
<Table.Cell>
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.
</Table.Cell>
<Table.Cell>
No
</Table.Cell>
<Table.Cell>
\-
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
`workerOptions`
</Table.Cell>
<Table.Cell>
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.
</Table.Cell>
<Table.Cell>
No
</Table.Cell>
<Table.Cell>
\-
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
`jobOptions`
</Table.Cell>
<Table.Cell>
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.
</Table.Cell>
<Table.Cell>
No
</Table.Cell>
<Table.Cell>
\-
</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 'event-redis' established