Meaning, they don't have to be distributed. I'm thinking about using memcached
or redis
for that. Probably the latter one. What I'm concerned about is "we've got to free some memory, so we'll delete this key/value before it expired" thing. But I'm open to other suggestions as well.
How to implement non-distributed locks which expire?
493 Views Asked by x-yuri At
1
There are 1 best solutions below
Related Questions in CONCURRENCY
- PySimpleGUI matplotlib graph not showing up as popup window,and is only showing the graph in the notebook
- How to integrate code with window in PySimpleGUI
- How to make columns in listbox?
- pysimplegui keyboard event returns question mark when pressing non-ascii character
- How to change the popup size in PysimpleGUI in python?
- PySimpleGUI sg.Radio button error: __init__() missing 1 required positional argument: 'group_id'
- PySimpleGUI - Login Authenticator
- How to clear a Matplotlib subplot canvas figure when a new radio button is clicked PySimpleGUI?
- Interactive matplotlib plot in PySimpleGUI
- How to resize sg.window in PYsimpleGUI?
Related Questions in REDIS
- PySimpleGUI matplotlib graph not showing up as popup window,and is only showing the graph in the notebook
- How to integrate code with window in PySimpleGUI
- How to make columns in listbox?
- pysimplegui keyboard event returns question mark when pressing non-ascii character
- How to change the popup size in PysimpleGUI in python?
- PySimpleGUI sg.Radio button error: __init__() missing 1 required positional argument: 'group_id'
- PySimpleGUI - Login Authenticator
- How to clear a Matplotlib subplot canvas figure when a new radio button is clicked PySimpleGUI?
- Interactive matplotlib plot in PySimpleGUI
- How to resize sg.window in PYsimpleGUI?
Related Questions in LOCKING
- PySimpleGUI matplotlib graph not showing up as popup window,and is only showing the graph in the notebook
- How to integrate code with window in PySimpleGUI
- How to make columns in listbox?
- pysimplegui keyboard event returns question mark when pressing non-ascii character
- How to change the popup size in PysimpleGUI in python?
- PySimpleGUI sg.Radio button error: __init__() missing 1 required positional argument: 'group_id'
- PySimpleGUI - Login Authenticator
- How to clear a Matplotlib subplot canvas figure when a new radio button is clicked PySimpleGUI?
- Interactive matplotlib plot in PySimpleGUI
- How to resize sg.window in PYsimpleGUI?
Related Questions in MEMCACHED
- PySimpleGUI matplotlib graph not showing up as popup window,and is only showing the graph in the notebook
- How to integrate code with window in PySimpleGUI
- How to make columns in listbox?
- pysimplegui keyboard event returns question mark when pressing non-ascii character
- How to change the popup size in PysimpleGUI in python?
- PySimpleGUI sg.Radio button error: __init__() missing 1 required positional argument: 'group_id'
- PySimpleGUI - Login Authenticator
- How to clear a Matplotlib subplot canvas figure when a new radio button is clicked PySimpleGUI?
- Interactive matplotlib plot in PySimpleGUI
- How to resize sg.window in PYsimpleGUI?
Related Questions in CONCURRENT-PROGRAMMING
- PySimpleGUI matplotlib graph not showing up as popup window,and is only showing the graph in the notebook
- How to integrate code with window in PySimpleGUI
- How to make columns in listbox?
- pysimplegui keyboard event returns question mark when pressing non-ascii character
- How to change the popup size in PysimpleGUI in python?
- PySimpleGUI sg.Radio button error: __init__() missing 1 required positional argument: 'group_id'
- PySimpleGUI - Login Authenticator
- How to clear a Matplotlib subplot canvas figure when a new radio button is clicked PySimpleGUI?
- Interactive matplotlib plot in PySimpleGUI
- How to resize sg.window in PYsimpleGUI?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
tl;dr Use ready-made solution, suggested by developers.
So, I decided not to use
memcached
for the purpose. Since it's a caching server. I don't see a way to ensure that it doesn't delete my keys because it's out of memory. With,redis
that's not an issue as long asmaxmemory-policy = noeviction
.There are 3 links I want to share with you. They are basically 3 ways, that I now know, to solve the issue. As long as you have
redis >= 2.6.0
that is.redis >= 2.6.12
If you've got
redis >= 2.6.12
, you're lucky and can simply usesetnx
command with its new optionsex
andnx
:But we can't just delete the lock in the end, if we are to allow for critical section taking longer then we expected (
>= ttl
). Consider the following situation:For that not to happen we are going to store current timestamp as a value of the lock. Then, knowing that Lua scripts are atomic (see Atomicity of scripts):
However, is it possible for two clients to have equal
now
values? For that all the above actions should happen within one second andttl
must be equal to0
.Resulting code:
expire
The other solution I found here. You simply make the value expire with
expire
command:So, only
acquire_lock
function changes:getset
And the last one is described again in documentation. Marked with "left for historical reasons" note.
This time we store timestamp of the moment when the lock is to expire. We store it with
setnx
command. If it succeeds, we've acquired the lock. Otherwise, either someone else's holding the lock, or the lock has expired. Be it the latter, we usegetset
to set new value and if the old value hasn't changed, we've acquired the lock:What makes me uncomfortable here is that we seem to have changed someone else's
expires_at
value, don't we?On a side note, you can check which
redis
is it that you're using this way:Some debugging functions: