Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
LibreChat employes 2 different Redis client libraries (built-in node.js client via Keyv, and ioredis) and 3 different Redis wrappers (@keyv/redis, rate-limit-redis, and connect-redis). It supports various Redis features like prefix, namespace, ttl, tls, cluster and so on but these features are not consistently applied to said redis libraries. Calls to instantiate redis cache stores are also also not centralized, leading to caching logic bleeding into other sections of the app.
This PR is an attempt to overhaul caching for LibreChat (esp Redis) for better maintainability, while fixing several features regarding Redis:
Configuration Management
api/cache/cacheConfig.js
is a one-stop-shop that reads and parses ENV vars used for caching.Architecture Improvements
api/cache/redisClients.js
replaces complex client creation logic in the oldioredisClient.js
andkeyvRedis.js
(notably using URL package to handle the complex parsing of the old mapURI function)api/cache/cacheFactory.js
provides unified cache creation methods (redisCache, sessionCache, violationCache, limiterCache)middleware/limiters
getLogStores
are now properly mapped to an enum value.Fixes for features that didn't work or weren't implemented consistently
I also added complete Redis cluster setup scripts and configurations in
redis-config/
to help with local testing of the above features. Check isredis-config/README.md
file for more details.Change Type
Testing
Please describe your test process and include instructions so that we can reproduce your test. If there are any important variables for your testing configuration, list them here.
Test Configuration:
Checklist
Please delete any irrelevant options.