SPSCommerce / redlock-py

Redis distributed locks in Python
MIT License
571 stars 117 forks source link

Question: how do you keep the lock #17

Open osallou opened 8 years ago

osallou commented 8 years ago

Once A has acquired the lock, set with a timeout of 10 seconds for example. How can A keep the lock, within the 10 seconds, to prevent B to take it? I see no method to renew the lock.

I expect A to keep the lock as long as necessary, then B takes it only if A fails (and ttl will remove the lock) or A releases the lock.

Thanks

optimuspaul commented 8 years ago

That does sound like a good feature request. My advice for now would be obtain locks with timeouts much longer than you expect you'd need.

I don't know if you'd read this, http://martin.kleppmann.com/2016/02/08/how-to-do-distributed-locking.html, but a lot of concerns about the safety of redlock have been brought up. I personally like the simplicity of redlock and in my use only use it for advice and not as a guarantee.

There is always the possibility that A fails to complete it's task before the timeout occurs, which is why you would never want to use redlock in a critical scenario unless you were also using a CAS of some sort to deal with conflict.

osallou commented 8 years ago

I indeed read article. A longer ttl will not fit for a process willing to keep forever until stopped, released or crashed. The random value obtained with the lock could be used certainly to allow an expiration update only if value match, just like for releasing it.

Le ven. 18 mars 2016 18:52, Paul DeCoursey notifications@github.com a écrit :

That does sound like a good feature request. My advice for now would be obtain locks with timeouts much longer than you expect you'd need.

I don't know if you'd read this, http://martin.kleppmann.com/2016/02/08/how-to-do-distributed-locking.html, but a lot of concerns about the safety of redlock have been brought up. I personally like the simplicity of redlock and in my use only use it for advice and not as a guarantee.

There is always the possibility that A fails to complete it's task before the timeout occurs, which is why you would never want to use redlock in a critical scenario unless you were also using a CAS of some sort to deal with conflict.

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/SPSCommerce/redlock-py/issues/17#issuecomment-198469762

xq5he commented 7 years ago

@osallou Actually, set will return null if the key has been set. So this check will be Flase if the resource has been locked by other client.