-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Description
Version: 4.3.x - 4.4.0rc2
Platform: Python 3.10 on Ubuntu 20.04
Description: AsyncIO Cluster mode doesn't seem to support Lock
Reproducible code is this
async def test_aiolock():
from redis.asyncio.lock import Lock as ALock
r: redis.asyncio.RedisCluster = aredis() # Async Redis cluster connection
counter = 0
async with ALock(
redis=r, name="test-lock", timeout=None, sleep=0.01, blocking=True
):
counter += 1
assert counter == 1Log is as follow
============================= test session starts ==============================
collecting ... collected 1 item
test_cache.py::test_aiolock FAILED [100%]
tests/test_cache.py:30 (test_aiolock)
async def test_aiolock():
from redis.asyncio.lock import Lock as ALock
r: redis.asyncio.RedisCluster = aredis()
counter = 0
> async with ALock(
redis=r, name="test-lock", timeout=None, sleep=0.01, blocking=True
):
test_cache.py:36:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../venv/lib/python3.10/site-packages/redis/asyncio/lock.py:147: in __init__
self.register_scripts()
../../venv/lib/python3.10/site-packages/redis/asyncio/lock.py:153: in register_scripts
cls.lua_release = client.register_script(cls.LUA_RELEASE_SCRIPT)
../../venv/lib/python3.10/site-packages/redis/commands/core.py:5204: in register_script
return AsyncScript(self, script)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <redis.commands.core.AsyncScript object at 0x7f6d92d03d30>
registered_client = <redis.asyncio.cluster.RedisCluster object at 0x7f6d933e6fb0>
script = "\n local token = redis.call('get', KEYS[1])\n if not token or token ~= ARGV[1] then\n return 0\n end\n redis.call('del', KEYS[1])\n return 1\n "
def __init__(self, registered_client: "AsyncRedis", script: ScriptTextT):
self.registered_client = registered_client
self.script = script
# Precalculate and store the SHA1 hex digest of the script.
if isinstance(script, str):
# We need the encoding from the client in order to generate an
# accurate byte representation of the script
> encoder = registered_client.connection_pool.get_encoder()
E AttributeError: 'RedisCluster' object has no attribute 'connection_pool'
../../venv/lib/python3.10/site-packages/redis/commands/core.py:4978: AttributeError
======================== 1 failed, 5 warnings in 0.25s =========================
Also, I think we can typehint async version of Lock to accept Async version of client only... now it looks like it also accepts blocking client too. (which doesn't work either with async version of Lock)