redis lock acquiring not working - stays running and never acquires

1.2k Views Asked by At

this is my code:

pool = aioredis.ConnectionPool.from_url("redis://localhost:6379")
redis = await aioredis.Redis(connection_pool=pool, ssl=False, ssl_cert_reqs="None")

async with redis.lock("hello_lock") as lock:
    print("hello")
    await redis.hset("hello", "1", "2")

the Context Manager never gets entered and it seems like the lock is not being acquired at all. The program stays running/stuck on this line: async with redis.lock("hello_lock") as lock:

Acquiring the lock should be a very quick thing so i'm confused whats happening here. Any help would be appreciated.

1

There are 1 best solutions below

0
Saxtheowl On

It might be a problem with the Redis lock implementation, try the following commands to manually acquire and release a lock:

127.0.0.1:6379> SET my_lock "1" NX
OK
127.0.0.1:6379> GET my_lock
"1"

If that still dont work try another method of lock like RedLock or RLock