{"id":23222,"library":"aioredlock","title":"aioredlock","description":"Asyncio implementation of Redis distributed locks, providing a reliable mutex mechanism for distributed systems. Current version 0.7.3, with low release cadence. Requires Python >=3.6.","status":"active","version":"0.7.3","language":"python","source_language":"en","source_url":"https://github.com/joanvila/aioredlock","tags":["redis","distributed-lock","asyncio","mutex"],"install":[{"cmd":"pip install aioredlock","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Required for Redis client.","package":"redis","optional":false},{"reason":"Required for async Redis client.","package":"aioredis","optional":false}],"imports":[{"note":"The main class is Aioredlock, not Lock. Lock is an internal class.","wrong":"from aioredlock import Lock","symbol":"Aioredlock","correct":"from aioredlock import Aioredlock"}],"quickstart":{"code":"import asyncio\nfrom aioredlock import Aioredlock\n\nasync def main():\n    # Initialize lock manager with Redis connection\n    lock_manager = Aioredlock([('localhost', 6379)])\n    \n    # Acquire a lock\n    lock = await lock_manager.lock(\"my_resource\")\n    if lock:\n        print(\"Lock acquired\")\n        # Do critical work\n        await asyncio.sleep(1)\n        # Release the lock\n        await lock_manager.unlock(lock)\n    else:\n        print(\"Failed to acquire lock\")\n    \n    # Cleanly close connections\n    await lock_manager.destroy()\n\nasyncio.run(main())","lang":"python","description":"Basic usage: acquire and release a distributed lock using aioredlock."},"warnings":[{"fix":"Always store the lock object from lock() and pass it to unlock().","message":"The unlock() method must be called with the lock object returned by lock(), not a string. Passing a string will raise an AttributeError.","severity":"gotcha","affected_versions":"all"},{"fix":"Use a try/finally block or context manager to ensure destroy() is called.","message":"The lock manager must be destroyed with await lock_manager.destroy() to close Redis connections. Forgetting to call destroy() will cause connection leaks.","severity":"gotcha","affected_versions":"all"},{"fix":"Pin aioredis<2 or consider migrating to a maintained alternative like redis-py (redis.asyncio).","message":"The library relies on aioredis v1.x, which is deprecated. aioredis v2.x changed the API significantly, but aioredlock has not been updated.","severity":"deprecated","affected_versions":"0.7.3"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use: from aioredlock import Aioredlock","cause":"Attempting to import Lock directly from aioredlock, but the correct class is Aioredlock.","error":"AttributeError: module 'aioredlock' has no attribute 'Lock'"},{"fix":"Ensure you store the lock object from lock() and pass it to unlock().","cause":"Passing a string (e.g., lock name) to unlock() instead of the lock object.","error":"TypeError: object str can't be used in 'await' expression"},{"fix":"Start Redis server or check connection parameters.","cause":"Redis server is not running or wrong host/port.","error":"aioredis.exceptions.ConnectionError: Error 111 connecting to localhost:6379. Connection refused."}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}