Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure Redis DB # explicitly? #298

Open
rbonestell opened this issue Jun 5, 2024 · 1 comment
Open

Configure Redis DB # explicitly? #298

rbonestell opened this issue Jun 5, 2024 · 1 comment

Comments

@rbonestell
Copy link

How can I choose which Redis DB number is used by node-redlock?

I have a perfectly good redis instance I'd like to use for redlock, but I don't want to pollute the data in DB #0 and I'd like to configure node-redlock to use another DB. Is this possible?

@rbonestell
Copy link
Author

For anyone else curious about the same functionality, at this point I am manually selecting the DB # on my ioredis Redis client instance prior to calling using() on my redlock instance which uses the Redis instance:

await this.redisClient.select(8);
await this.redlock.using(ids, lockDuration, func);

My only remaining concern is that I intended to share the Redis client instance as a singleton across my application, and there's a non-zero chance for a race condition where another call to the same Redis client could set the DB to something other than 8 prior to the using() executing.

In the meantime, I have initialized another bespoke instance of the Redis client specifically for use with the redlock instance.

I would like to see a configurable dbNumber value in node-redlock which accepts the DB # and utilizes it in the Lua scripts directly to ensure no susceptibility to race conditions on the same Redis client instance. If dbNumber is not provided then it should default to 0 for backwards compatibility and to ensure support for services such as AWS Serverless Elasticache, which only support 1 Redis DB (DB 0).

@rbonestell rbonestell changed the title Choose which Redis DB # is used? Configure Redis DB # explicitly? Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant