medusajs / medusa

Building blocks for digital commerce
https://medusajs.com
MIT License
23.68k stars 2.28k forks source link

Cache redis should not use KEYS command #7551

Open nicolama-dev opened 1 month ago

nicolama-dev commented 1 month 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 4 weeks ago

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