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

Idea: support N lock holders #42

Open
sc0rp10 opened this issue Mar 8, 2016 · 4 comments
Open

Idea: support N lock holders #42

sc0rp10 opened this issue Mar 8, 2016 · 4 comments

Comments

@sc0rp10
Copy link

sc0rp10 commented Mar 8, 2016

Such as Consul offers:

An example use case is for highly-available N+1 deployments. In these cases, if N instances of a service are required, N+1 are deployed and use consul lock with -n=N to ensure only N instances are running. For singleton services, a hot standby waits until the current leader fails to take over.

@AndreiPashkin
Copy link
Contributor

Sounds like a semaphore.

@sc0rp10
Copy link
Author

sc0rp10 commented Mar 9, 2016

yes, sure, it's semaphore inside, but would be nice have two lock realizatons with same interface.

@ionelmc
Copy link
Owner

ionelmc commented Mar 9, 2016

I would rather keep this library focused on its initial goal: a fast and robust lock for redis.

I don't have anything against implementing a semaphore but it seems to me that it would be better implemented in another library. Plus it's confusing, why would lock library implement a semaphore?

@sc0rp10
Copy link
Author

sc0rp10 commented Mar 9, 2016

My little case: I need library, that can use Locks if holder=1 and use semaphore if holder=2-N: i don't like write code such as:

if holder == 1:
    with redis_lock.Lock(r, key):
        do_cricical_section()
else:
    with redis_lock.Semaphore(r, key, holder):
        do_cricical_section()

I prefer other approach:

with redis_lock.CommonLock(r, key, holder): # inside if holders > 1 using semaphore, otherwise - simple lock
    do_cricical_section()

Your library is the best among its competitors, would be nice if inside her will be implemented other synchronization primitives.

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

3 participants