{ "info": { "author": "Joan Vil\u00e0 Cu\u00f1at", "author_email": "vila.joan94@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "aioredlock\n==========\n\n.. image:: https://travis-ci.org/joanvila/aioredlock.svg?branch=master\n :target: https://travis-ci.org/joanvila/aioredlock\n\n.. image:: https://codecov.io/gh/joanvila/aioredlock/branch/master/graph/badge.svg\n :target: https://codecov.io/gh/joanvila/aioredlock\n\n.. image:: https://badge.fury.io/py/aioredlock.svg\n :target: https://pypi.python.org/pypi/aioredlock\n\nThe asyncio redlock_ algorithm implementation.\n\nRedlock and asyncio\n-------------------\n\nThe redlock algorithm is a distributed lock implementation for Redis_. There are many implementations of it in several languages. In this case, this is the asyncio_ compatible implementation for python 3.5+.\n\n\nUsage\n-----\n.. code-block:: python\n\n from aioredlock import Aioredlock, LockError\n\n # Define a list of connections to your Redis instances:\n redis_instances = [\n ('localhost', 6379),\n {'host': 'localhost', 'port': 6379, 'db': 1},\n 'redis://localhost:6379/2',\n ]\n\n # Create a lock manager:\n lock_manager = Aioredlock(redis_instances)\n\n # Check wether a resourece acquired by any other redlock instance:\n assert not await lock_manager.is_locked(\"resource_name\")\n\n # Try to acquire the lock:\n try:\n lock = await lock_manager.lock(\"resource_name\")\n except LockError:\n print('Lock not acquired')\n raise\n\n # Now the lock is acquired:\n assert lock.valid\n assert await lock_manager.is_locked(\"resource_name\")\n\n # Extend lifetime of the lock:\n await lock_manager.extend(lock)\n # Raises LockError if the lock manager can not extend the lock lifetime\n # on more then half of the Redis instances.\n\n # Release the lock:\n await lock_manager.unlock(lock)\n # Raises LockError if the lock manager can not release the lock\n # on more then half of redis instances.\n\n # The released lock become invalid:\n assert not lock.valid\n assert not await lock_manager.is_locked(\"resource_name\")\n\n # Or you can use the lock as async context manager:\n try:\n async with await lock_manager.lock(\"resource_name\") as lock:\n assert lock.valid is True\n # Do your stuff having the lock\n await lock.extend() # alias for lock_manager.extend(lock)\n # Do more stuff having the lock\n assert lock.valid is False # lock will be released by context manager\n except LockError:\n print('Lock not acquired')\n raise\n\n # Clear the connections with Redis:\n await lock_manager.destroy()\n\n\nHow it works\n------------\n\nThe Aioredlock constructor accepts the following optional parameters:\n\n- ``redis_connections``: A list of connections (dictionary of host and port and kwargs for ``aioredis.create_redis_pool()``, or tuple ``(host, port)``, or sting Redis URI) where the Redis instances are running. The default value is ``[{'host': 'localhost', 'port': 6379}]``.\n- ``lock_timeout``: An float (in seconds) representing lock validity period. The default value is ``10.0`` seconds.\n- ``drift``: An float for clock drift compensation. The default value is calculated by ``lock_timeout * 0.01 + 0.002`` seconds.\n- ``retry_count``: An integer representing number of maximum allowed retries to acquire the lock. The default value is ``3`` times.\n- ``retry_delay_min`` and ``retry_delay_max``: Float values representing waiting time (in seconds) before the next retry attempt. The default values are ``0.1`` and ``0.3``, respectively.\n\nIn order to acquire the lock, the ``lock`` function should be called. If the lock operation is successful, ``lock.valid`` will be true, if the lock is not acquired then the ``LockError`` will be raised.\n\nFrom that moment, the lock is valid until the ``unlock`` function is called or when the ``lock_timeout`` is reached.\n\nCall the ``extend`` function to reset lifetime of the lock to ``lock_timeout`` interval.\n\nUse the ``is_locked`` function to check if the resource is locked by other redlock instance.\n\nIn order to clear all the connections with Redis, the lock_manager ``destroy`` method can be called.\n\nTo-do\n-----\n\n* Expire the lock valid attribute according to the lock validity in a safe way if possible\n\n.. _redlock: https://redis.io/topics/distlock\n.. _Redis: https://redis.io\n.. _asyncio: https://docs.python.org/3/library/asyncio.html\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/joanvila/aioredlock", "keywords": "redis redlock distributed locks asyncio", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "aioredlock", "package_url": "https://pypi.org/project/aioredlock/", "platform": "", "project_url": "https://pypi.org/project/aioredlock/", "project_urls": { "Homepage": "https://github.com/joanvila/aioredlock" }, "release_url": "https://pypi.org/project/aioredlock/0.3.0/", "requires_dist": [ "aioredis", "attrs (>=17.4.0)" ], "requires_python": "", "summary": "Asyncio implemetation of Redis distributed locks", "version": "0.3.0" }, "last_serial": 4699561, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "e22520f67fdf9359df4ee432a07b9e5d", "sha256": "30421e1a081c63275d8de4171945abeba056e6119628e20be1fcba730cc5ea83" }, "downloads": -1, "filename": "aioredlock-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "e22520f67fdf9359df4ee432a07b9e5d", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6448, "upload_time": "2017-03-19T09:32:32", "url": "https://files.pythonhosted.org/packages/91/47/5b3ef5900a1d8b2c9fbf6e75121f487b47f19c0ab4bcdafea5afda123d51/aioredlock-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "11c3b7f302d4da5add4456c72dde8911", "sha256": "231c7d319401d9a28dd2f81e4c495bfb1b44088f003f9c327e5f216ede3e6110" }, "downloads": -1, "filename": "aioredlock-0.0.1.tar.gz", "has_sig": false, "md5_digest": "11c3b7f302d4da5add4456c72dde8911", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3850, "upload_time": "2017-03-05T12:35:54", "url": "https://files.pythonhosted.org/packages/b1/0f/f0a259f0ea7dd1285a2baa776c70856782105f61ca0f52186156d1b12928/aioredlock-0.0.1.tar.gz" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "c818dc2e19f3262c7e53ad8955dd72d5", "sha256": "82d8b39499ddeb3a73aeca23b6efd4ad07ce277572093c9b5c744c50f0414158" }, "downloads": -1, "filename": "aioredlock-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "c818dc2e19f3262c7e53ad8955dd72d5", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6636, "upload_time": "2017-03-19T09:32:36", "url": "https://files.pythonhosted.org/packages/00/f9/273485fff3d17137600337dd70971d05269a7548a17d193b062e4eeaf2eb/aioredlock-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "2b7bd7f16426491ff67c0f057afaa2ad", "sha256": "8c4d90241818e4e1680cadc41cd47dc0293b812b73c5ba4ff3408136a23292a1" }, "downloads": -1, "filename": "aioredlock-0.1.0.tar.gz", "has_sig": false, "md5_digest": "2b7bd7f16426491ff67c0f057afaa2ad", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4054, "upload_time": "2017-03-19T09:37:28", "url": "https://files.pythonhosted.org/packages/88/53/f3cf80e9e7a1d84bbe6bed944a17139b33263ecdb1bf256d15bb852e0fdd/aioredlock-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "cd45bcff9beaa309b1afd7ac58022521", "sha256": "114bdf25d367e2e4cf855e48e5477badb89eefdcea583de757044635cb4afce2" }, "downloads": -1, "filename": "aioredlock-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "cd45bcff9beaa309b1afd7ac58022521", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6647, "upload_time": "2017-05-14T11:09:37", "url": "https://files.pythonhosted.org/packages/e3/ec/b774f98fccdd7e4bf8c1b786f9ef4d73083b12fee2b43de162243b11e34e/aioredlock-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a5fd5434c50757bfd6ab4b816b2af9b7", "sha256": "2b15c9515fc0143bb8c26de059c04f839e4af3ff421741042558a5f540e188f6" }, "downloads": -1, "filename": "aioredlock-0.1.1.tar.gz", "has_sig": false, "md5_digest": "a5fd5434c50757bfd6ab4b816b2af9b7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4082, "upload_time": "2017-05-14T11:09:39", "url": "https://files.pythonhosted.org/packages/3c/08/ab0a71102aafe2cffe5f82aa9026908411716e5292d2fc4299c16437409f/aioredlock-0.1.1.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "a2843788aa6401f13adc96a6d3128529", "sha256": "9cba72ce02e2359f7efc33642cf68f57915775be796b3215e7847c3458a92002" }, "downloads": -1, "filename": "aioredlock-0.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "a2843788aa6401f13adc96a6d3128529", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 10562, "upload_time": "2018-03-23T23:43:04", "url": "https://files.pythonhosted.org/packages/10/38/80f29068e9a43b7c01564f74bcbc6532726656ca90beca4911f49b1270cd/aioredlock-0.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e580b2499cbd7a20e1c656776942ad97", "sha256": "046abdad14bd33dfcaf47d5d2f792ecc3489613a4ae7faba075a8226c0a7f56a" }, "downloads": -1, "filename": "aioredlock-0.2.0.tar.gz", "has_sig": false, "md5_digest": "e580b2499cbd7a20e1c656776942ad97", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8030, "upload_time": "2018-03-23T23:43:05", "url": "https://files.pythonhosted.org/packages/71/d3/1ed4d1c64e698013963fb393411fb242499d2f794d7f35bacd3e9cb0ddd7/aioredlock-0.2.0.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "a2763ca610253adfa382a425d1dede06", "sha256": "03f38752960d5340b4343ef18f60e849f007d5584a3da36009b72d3e12421cba" }, "downloads": -1, "filename": "aioredlock-0.2.1-py3-none-any.whl", "has_sig": false, "md5_digest": "a2763ca610253adfa382a425d1dede06", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 10585, "upload_time": "2018-09-07T20:42:30", "url": "https://files.pythonhosted.org/packages/f9/02/fdbfd316a3fd77ac7dad0365a308619269471f0c4056e772477ec02e0a31/aioredlock-0.2.1-py3-none-any.whl" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "0a051591e58794f37db6c110468dd621", "sha256": "cd4e776d756b69d4cece192bfef50789b169a478abc22ab911cfaf40a19700e6" }, "downloads": -1, "filename": "aioredlock-0.3.0-py3-none-any.whl", "has_sig": false, "md5_digest": "0a051591e58794f37db6c110468dd621", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 10520, "upload_time": "2019-01-15T16:35:59", "url": "https://files.pythonhosted.org/packages/64/25/9c1bbba386f34bb02714a76c78f28df9a3120b261931e8b8f2ef95050499/aioredlock-0.3.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "16ef13e25a5edf2ce4c193398a1fec4d", "sha256": "5e25106b46f114b34a2dcf53c085ecfdf3633c4ba1ccc78539df43748e3f7455" }, "downloads": -1, "filename": "aioredlock-0.3.0.tar.gz", "has_sig": false, "md5_digest": "16ef13e25a5edf2ce4c193398a1fec4d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7989, "upload_time": "2019-01-15T16:36:01", "url": "https://files.pythonhosted.org/packages/8b/69/93469783b4b98a110efd4c73b085762d0c964ecdbf5fcf74e5a9ac398f2f/aioredlock-0.3.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "0a051591e58794f37db6c110468dd621", "sha256": "cd4e776d756b69d4cece192bfef50789b169a478abc22ab911cfaf40a19700e6" }, "downloads": -1, "filename": "aioredlock-0.3.0-py3-none-any.whl", "has_sig": false, "md5_digest": "0a051591e58794f37db6c110468dd621", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 10520, "upload_time": "2019-01-15T16:35:59", "url": "https://files.pythonhosted.org/packages/64/25/9c1bbba386f34bb02714a76c78f28df9a3120b261931e8b8f2ef95050499/aioredlock-0.3.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "16ef13e25a5edf2ce4c193398a1fec4d", "sha256": "5e25106b46f114b34a2dcf53c085ecfdf3633c4ba1ccc78539df43748e3f7455" }, "downloads": -1, "filename": "aioredlock-0.3.0.tar.gz", "has_sig": false, "md5_digest": "16ef13e25a5edf2ce4c193398a1fec4d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7989, "upload_time": "2019-01-15T16:36:01", "url": "https://files.pythonhosted.org/packages/8b/69/93469783b4b98a110efd4c73b085762d0c964ecdbf5fcf74e5a9ac398f2f/aioredlock-0.3.0.tar.gz" } ] }