medusajs / medusa

The world's most flexible commerce platform.
https://medusajs.com
MIT License
25.93k stars 2.6k forks source link

Cache redis should not use KEYS command #7551

Closed nicolama-dev closed 1 month ago

nicolama-dev commented 5 months ago

Bug report

Describe the bug

In cache-redis the invalidate function is using KEYS command.

const keys = await this.redis.keys(this.getCacheKey(key))

This command is highly NOT recommended for production setup because it can block the redis server if we have a large amount of keys stored in cache. As a matter of fact Upstash is ignoring KEYS commands when redis sizes > 100k keys.

I experienced myself a degraded Medusa performance with query sometimes hitting 10/15s response time due to this issue.

Below you can find articles from Upstash and Redis advising to use the SCAN command instead that will split the search in several commands:

Upstash article and Redis article

sradevski commented 5 months ago

Thanks for raising this @nicolama-dev, we'll make sure to address it in v2 👍

github-actions[bot] commented 1 month ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 3 days.

carlos-r-l-rodrigues commented 1 month ago

issue addressed on https://github.com/medusajs/medusa/pull/9544