SPSCommerce / redlock-py

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

Add watching dog to extend TTL #30

Open TsingJyujing opened 4 years ago

TsingJyujing commented 4 years ago

I'd like to implement a function like we can extend a lock every N secs, the purpose to do that is designed for some transaction that can't control the timeout, but we also want the lock be released while the server is down.

Do you have any advice?

eedalong commented 4 years ago

@TsingJyujing

  1. if u want to use watchdog feature, u can just use redission with java
  2. I've been thinking about this problem this morning, and I came to a rough conclusion that, if we dont want write a new redis client, maybe multithread can be one of the solutions to this problem.I mean use another thread to check and extend the lock for N secs. This can ensure that a) if the server goes down, the thread also dies, and the lock will not be extended, so the lock can be auto released by redis however, this solution may have some bad effect on the performance of the worker thread.
TsingJyujing commented 4 years ago

@eedalong Thank you for reply!!!!

I can't use Java because I'm writing a server with Python (the deep reason is PIL is convient in Python and Java do not have a such useful lib).

And I think it's also tricky to stop/kill the thread, I think we should use context manager to make a high level API to manage these troublism things like we described in #25 .

If you have intention to make this high level API, I'd like to make a PR, how about you idea?

eedalong commented 4 years ago

@TsingJyujing check this out https://zhuanlan.zhihu.com/p/101913195

brainix commented 3 years ago

Pottery’s implementation of Redlock has an .extend() method that does what you’re looking for. Disclaimer: I develop/maintain Pottery. Good luck!