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

Redis cluster lock #238

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions beaker/ext/redisclusternm.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ class RedisClusterSynchronizer(RedisSynchronizer):

This Synchronizer only supports 1 reader or 1 writer at time, not concurrent readers.
"""
RELEASE_LOCK_LUA = """
if redis.call('get', KEYS[1]) == ARGV[1] then
return redis.call('del', KEYS[1])
else
return 0
end
"""

def __init__(self, identifier, urls, nodes=None, **kwargs):
super(RedisSynchronizer, self).__init__()
Expand All @@ -85,3 +92,9 @@ def __init__(self, identifier, urls, nodes=None, **kwargs):
)
else:
self.client = urls
self._release_lock = self.client.register_script(self.RELEASE_LOCK_LUA)

def do_release_write_lock(self):
identifier = self.identifier
owner_id = self._get_owner_id()
self._release_lock(keys=[identifier], args=[owner_id])
Loading