From fe69d0723dc629f70c8ee3778cf67cecaadfd9d7 Mon Sep 17 00:00:00 2001 From: Alessandro Molina Date: Tue, 9 Apr 2024 19:28:28 +0000 Subject: [PATCH 1/2] experimental implementation of lock on cluster --- beaker/ext/redisclusternm.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/beaker/ext/redisclusternm.py b/beaker/ext/redisclusternm.py index 0024ae8..ba679c8 100644 --- a/beaker/ext/redisclusternm.py +++ b/beaker/ext/redisclusternm.py @@ -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__() @@ -85,3 +92,9 @@ def __init__(self, identifier, urls, nodes=None, **kwargs): ) else: self.client = urls + self._release_lock = self.client.register_lua(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]) \ No newline at end of file From df84e922ae6f132c6d0480ce95703eb021fd6448 Mon Sep 17 00:00:00 2001 From: Alessandro Molina Date: Tue, 9 Apr 2024 19:36:44 +0000 Subject: [PATCH 2/2] wrong function name --- beaker/ext/redisclusternm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beaker/ext/redisclusternm.py b/beaker/ext/redisclusternm.py index ba679c8..96a43d5 100644 --- a/beaker/ext/redisclusternm.py +++ b/beaker/ext/redisclusternm.py @@ -92,7 +92,7 @@ def __init__(self, identifier, urls, nodes=None, **kwargs): ) else: self.client = urls - self._release_lock = self.client.register_lua(self.RELEASE_LOCK_LUA) + self._release_lock = self.client.register_script(self.RELEASE_LOCK_LUA) def do_release_write_lock(self): identifier = self.identifier