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

Locking then deleting multiple resources #68

Closed
ZacharyKearns opened this issue Mar 26, 2020 · 1 comment
Closed

Locking then deleting multiple resources #68

ZacharyKearns opened this issue Mar 26, 2020 · 1 comment
Labels

Comments

@ZacharyKearns
Copy link

Hi,

I want to lock multiple resources so they can't be accessed while I am deleting them.
The code looks something like this:

const lock = await redlock.lock(['lock:resource1', 'lock:resource2'], 1000);
redis.del(['resource1', 'resource2']);
await lock.unlock();

Also for my case, it can't be guaranteed that all the resources will exist in the cache.
Will this work?

When I run the code I get the following warning:

node_redis: Deprecated: The EVAL command contains a argument of type Array.
This is converted to "lock:resource1,lock:resource2" by using .toString() now and will return an error from v.3.0 on.
Please handle this in your code to make sure everything works as you intended it to.
@mike-marcacci
Copy link
Owner

Hi @ZacharyKearns, your general description here is correct usage of this library. Your example, though, would work just perfectly without locking at all, as deleting redis keys happens atomically already. This library is usually used when you have multi-step asynchronous operations on some shared state. Hope that answers your question!

RE the node_redis error, that indeed looks like a problem. I would highly suggest using ioredis instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants