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

Could I obtain multi resource by one lock? #28

Closed
sunkuo opened this issue Jan 11, 2017 · 3 comments
Closed

Could I obtain multi resource by one lock? #28

sunkuo opened this issue Jan 11, 2017 · 3 comments
Labels

Comments

@sunkuo
Copy link

sunkuo commented Jan 11, 2017

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.

@mike-marcacci
Copy link
Owner

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!

@sunkuo
Copy link
Author

sunkuo commented Mar 6, 2017

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.

@mike-marcacci
Copy link
Owner

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!

mike-marcacci pushed a commit that referenced this issue Jun 13, 2019
* 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
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