-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Description
What Medusa version and documentation are you using?
v2
Preliminary Checks
- This issue is not a duplicate. Before opening a new issue, please search existing issues: https://github.com/medusajs/medusa/issues
Issue Summary
Our Redis instance spiked using 3.82GB of memory with over 1.3M keys. Investigation showed that 1.29M keys (99%) are RedisEventBusService entries that have accumulated over the past 6 weeks with no cleanup. We thought this is because we had a scheduled job that ran daily at 3 AM, emitting vendor.pricing.update events for batch processing (~30,000 events/day). Without a retention policy, these events were not getting purged from Redis. We were under the impression all redis events had a ttl by default. However, upon understanding BullMQ and its relationship with Redis, we realized that BullMQ's default is removeOnComplete = true. But that doesn't actually mean events are deleted it just marks them as eligible to be deleted. Without {age, count} object, lazy cleanup never triggers.
How can this issue be resolved?
- We added this to our medusa-config.ts
{ resolve: '@medusajs/medusa/event-bus-redis', options: { redisUrl: process.env.REDIS_URL, jobOptions: { removeOnComplete: { age: 3600, // Remove completed jobs after 1 hour count: 1000, // Keep max 1000 completed jobs }, removeOnFail: { age: 86400, // Remove failed jobs after 24 hours count: 5000, // Keep max 5000 failed jobs }, }, }, },
Are you interested in working on this issue?
- I would like to fix this issue