Allow opt out of redlock in redis cacher #1192
Merged
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.
📝 Description
Currently, the Redis cacher will always try to instantiate a redlock instance if the dependency is able to be resolved. Currently, moleculer is only compatible with
^4.0.0
. The current version of redlock is5.0.0-beta.2
and moleculer is not compatible with it. However, if moleculer users with to use the current version of redlock while using the Redis cacher, they will experience errors when the cacher gets instantiated that prevent the broker from starting. This happens whether consumers wish to make use of the redlock functionality in moleculer or not.This PR allows consumers to opt-out of using redlock in the Redis cacher by setting the
opts.redlock
tofalse
. This was done to avoid any breaking changes.Additionally, this PR added a little more safety around use of the
lock
andtryLock
methods in the cacher. If redlock is not installed or was disabled, those methods would currently error because they would be accessing something not instantiated. Those methods will now log an error and resolve instead.💎 Type of change
🚦 How Has This Been Tested?
New unit tests were added and existing unit tests continue to pass.
🏁 Checklist: