feat(db): select Redis DB index on single-instance non-cluster configurations #10
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.
I discovered this repository from the original, where I had opened an issue regarding the inability to select a specific Redis DB index for use with Redlock in single-instance configurations with cluster mode disabled: mike-marcacci/node-redlock#298
I realized after browsing other issues and open PRs that the other repository was stale and no longer actively maintained. As a result I found this repo! I am happy to see all of the enhancements and the activity on this repository, and want to contribute my enhancements:
db
property toSettings
class options. Defaults to0
when omitted or provided with an invalid value.redis.pcall("SELECT", tonumber(ARGV[1]))
to attempt to select the DB index, which will silently no-op for configurations which don't support theSELECT
command or multiple DB indexes (Redis instances with cluster mode enabled).SELECT
command is specifically executed in each script because I have experienced several instances where using a shared ioredisRedis
client instance in my app's dependency container has lead to a race condition where records destined for another DB index end up in the Redlock specific DB index, and vis-versa. Performing the select in the script essentially ensures an atomic execution of the DB select along with the script.unit.spec.ts
) to project to cover Redlock settings test cases and Redlockacquire()
,extend()
, andrelease()
use cases with mocks.index.spec.ts
tosystem.spec.ts
to distinguish system tests from unit tests.db
settings option and behavior, and to correct invalid example import statements for ioredis (import Client from "ioredis";
does not work with the current version, whileimport Redis from "ioredis";
does).braces
:ℹ️ Also note, there is no CONTRIBUTING.md file in this repo despite the README.md file linking to one. (An artifact of the old repository contents, perhaps?)