-
Notifications
You must be signed in to change notification settings - Fork 172
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
Could I obtain multi resource by one lock? #28
Comments
Hi @sunkuo – sorry for the delay here. This is a great use case here, and I would probably recommend attempting to acquire multiple independent locks in parallel, releasing all acquired ones if one fails. This is definitely something that is generic and probably pretty common, so if you did end up implementing this in a generic way, send a PR – it would probably make a great convenience function to redlock! That's something I'll think about implementing as I have time! |
Hello,marcacci. Nice to hear from you . I think it is realizable with the command msetnx and del . I will try implement it this week. |
Just cleaning out old issues here; please feel free to reopen if this is still a problem, or a PR if you were able to solve this in a generic way! |
* Add support for locking multiple resources Locking of multiple resources in single call is "hard" due to nature of redis. Even when using MULTI (transaction support) all commands which are queued successfully will be executed (so we can't rely on redis to fail on already set key). This commit provides a sort-of-workaround by checking existence of values but it still doesn't provide strong guarantees for settings/removing/extending all resources. Ref #28 * Change idention to tabs * And rework some more tabs * Tab Tab * Set nil on lock error and check value diff on del * Add multivalue tests
Hey, man, would it be better if i can obtain multi resource by one lock . Think about this use case :
In a shopping application , when a user place order with multi sku and count, it is a good idea to use redlock to lock the sku and judge is there enough inventory to sell.
The text was updated successfully, but these errors were encountered: