Skip to content

Commit

Permalink
Redis cluster lock (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
amol- authored Apr 9, 2024
1 parent 0dfc877 commit 9ad1806
Showing 1 changed file with 13 additions and 0 deletions.
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])

0 comments on commit 9ad1806

Please sign in to comment.