{ "info": { "author": "Matt Rasband", "author_email": "matt.rasband@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: Implementation :: CPython" ], "description": "# aioredis_lock\n\n[![CircleCI](https://circleci.com/gh/mrasband/aioredis-lock.svg?style=svg)](https://circleci.com/gh/mrasband/aioredis-lock)\n\nImplementation of distributed locking with [aioredis](https://github.com/aio-libs/aioredis), an asyncio based redis client.\n\nThis is a standalone lib until, and if, [aio-libs/aioredis#573](https://github.com/aio-libs/aioredis/pull/573) is accepted.\n\n## Usage\n\nYou need an `aioredis.RedisConnection` or `aioredis.ConnectionsPool` already created.\n\n### Mutex\n\n```python\nfrom aioredis_lock import RedisLock, LockTimeoutError\n\ntry:\n async with RedisLock(\n pool,\n key=\"foobar\",\n # how long until the lock should expire (seconds). this can be extended\n # via `await lock.extend(30)`\n timeout=30,\n # you can customize how long to allow the lock acquisitions to be\n # attempted.\n wait_timeout=30,\n ) as lock:\n # If you get here, you now have a lock and are the only program that\n # should be running this code at this moment.\n\n # do some work...\n\n # we may want it longer...\n await lock.extend(30)\n\nexcept LockTimeoutError:\n # The lock could not be acquired by this worker and we should give up\n pass\n```\n\n### Simple Leader/Follower(s)\n\nLet's suppose you need a simple leader/follower type implementation where you have a number of web-workers but just want 1 to preform a repeated task. In the case the leader fails someone else should pick up the work. Simply pass `wait_timeout=None` to RedisLock allowing the worker to keep trying to get a lock for when the leader eventually fails. The main complication here is extending the lock and validating the leader still owns it.\n\n```python\nfrom aioredis_lock import RedisLock\n\n# if the lock is lost, we still want to be a follower\nwhile True:\n\n # wait indefinitely to acquire a lock\n async with RedisLock(pool, \"shared_key\", wait_timeout=None) as lock:\n\n # hold the lock as long as possible\n while True:\n if not await lock.is_owner():\n logger.debug(\"We are no longer the lock owner, falling back\")\n break\n\n # do some work\n\n if not await lock.renew():\n logger.debug(\"We lost the lock, falling back to follower mode\")\n break\n```\n\nThis mostly delegates the work of selecting and more importantly promoting leaders.\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/mrasband/aioredis-lock", "keywords": "aioredis,redis,locking,distributed,asyncio", "license": "", "maintainer": "", "maintainer_email": "", "name": "aioredis-lock", "package_url": "https://pypi.org/project/aioredis-lock/", "platform": "", "project_url": "https://pypi.org/project/aioredis-lock/", "project_urls": { "Homepage": "https://github.com/mrasband/aioredis-lock" }, "release_url": "https://pypi.org/project/aioredis-lock/0.0.3/", "requires_dist": [ "aioredis" ], "requires_python": ">=3.7", "summary": "Wrapper to provide distributed locks in aioredis", "version": "0.0.3" }, "last_serial": 5465834, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "16115d7dd47d2a739d62e1b873e89faf", "sha256": "7a071227f44f737ba16ff4f98b647517ea48a22fd3b050f7c53de3358c08d8a7" }, "downloads": -1, "filename": "aioredis-lock-0.0.1.tar.gz", "has_sig": false, "md5_digest": "16115d7dd47d2a739d62e1b873e89faf", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7", "size": 4566, "upload_time": "2019-06-09T13:09:39", "url": "https://files.pythonhosted.org/packages/a3/66/9e72c6f2197ebe832d4c72597b0cc88fe9b5ef127b6e40c1a7b1b06b2d13/aioredis-lock-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "b8dd7ef307e5e09ebf29eb8c73732184", "sha256": "268ae9f6d8cae941e90cc8559191d746e53e2b1d8e328e5c40a3b6577b30dc08" }, "downloads": -1, "filename": "aioredis_lock-0.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "b8dd7ef307e5e09ebf29eb8c73732184", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7", "size": 6209, "upload_time": "2019-06-29T14:36:42", "url": "https://files.pythonhosted.org/packages/90/e1/101914eae8634e658e81490a514a28e9dd860f52c0589e99693c0bb83616/aioredis_lock-0.0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8bf6bf56e74ef56ca41bdbc6961c51cb", "sha256": "5cae9adf391ad5b00e7bd6120a2b79c7a25adbf21069224953c27f481cc3018c" }, "downloads": -1, "filename": "aioredis-lock-0.0.2.tar.gz", "has_sig": false, "md5_digest": "8bf6bf56e74ef56ca41bdbc6961c51cb", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7", "size": 4608, "upload_time": "2019-06-29T14:36:44", "url": "https://files.pythonhosted.org/packages/8d/aa/fd4754334ddd2869a5df23405c255d6aed62b4453c695cb38bc7dfbbfe4e/aioredis-lock-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "1a930d220f272fb106d2c5c0664ea521", "sha256": "e99491c9589ba04c6144505eb9a3fa8a8cd0dbdd31257b5043eb06e6110af2af" }, "downloads": -1, "filename": "aioredis_lock-0.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "1a930d220f272fb106d2c5c0664ea521", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7", "size": 6204, "upload_time": "2019-06-29T16:37:48", "url": "https://files.pythonhosted.org/packages/96/a4/9cae5410ecf0ca3cf43798cfdce249d9fd41c2a67432b59c52bd35e46a64/aioredis_lock-0.0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c07f57ed55c3f5fc46219d177ac6c0b3", "sha256": "ff927b0970abfcfbc77612567e8d9e82a4403f8a95b1658d9e1fec0d0dc35cf6" }, "downloads": -1, "filename": "aioredis-lock-0.0.3.tar.gz", "has_sig": false, "md5_digest": "c07f57ed55c3f5fc46219d177ac6c0b3", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7", "size": 4616, "upload_time": "2019-06-29T16:37:50", "url": "https://files.pythonhosted.org/packages/36/b6/d5c1a56fd9b8814e784e10036a976fa7508dc67deb83af4208ecedc2e358/aioredis-lock-0.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "1a930d220f272fb106d2c5c0664ea521", "sha256": "e99491c9589ba04c6144505eb9a3fa8a8cd0dbdd31257b5043eb06e6110af2af" }, "downloads": -1, "filename": "aioredis_lock-0.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "1a930d220f272fb106d2c5c0664ea521", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7", "size": 6204, "upload_time": "2019-06-29T16:37:48", "url": "https://files.pythonhosted.org/packages/96/a4/9cae5410ecf0ca3cf43798cfdce249d9fd41c2a67432b59c52bd35e46a64/aioredis_lock-0.0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c07f57ed55c3f5fc46219d177ac6c0b3", "sha256": "ff927b0970abfcfbc77612567e8d9e82a4403f8a95b1658d9e1fec0d0dc35cf6" }, "downloads": -1, "filename": "aioredis-lock-0.0.3.tar.gz", "has_sig": false, "md5_digest": "c07f57ed55c3f5fc46219d177ac6c0b3", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7", "size": 4616, "upload_time": "2019-06-29T16:37:50", "url": "https://files.pythonhosted.org/packages/36/b6/d5c1a56fd9b8814e784e10036a976fa7508dc67deb83af4208ecedc2e358/aioredis-lock-0.0.3.tar.gz" } ] }