diff options
| author | CoprDistGit <infra@openeuler.org> | 2023-04-11 09:24:17 +0000 |
|---|---|---|
| committer | CoprDistGit <infra@openeuler.org> | 2023-04-11 09:24:17 +0000 |
| commit | 32a959c84345b2be17d3c86db96b3ae0e218179e (patch) | |
| tree | 138d656ed27671c36b1e7a87a9fa680c1f6262a6 /python-redlock.spec | |
| parent | 821264a2bb6f6c79b6522ab11c7f0e242b0f356b (diff) | |
automatic import of python-redlock
Diffstat (limited to 'python-redlock.spec')
| -rw-r--r-- | python-redlock.spec | 327 |
1 files changed, 327 insertions, 0 deletions
diff --git a/python-redlock.spec b/python-redlock.spec new file mode 100644 index 0000000..ee6c046 --- /dev/null +++ b/python-redlock.spec @@ -0,0 +1,327 @@ +%global _empty_manifest_terminate_build 0 +Name: python-redlock +Version: 1.2.0 +Release: 1 +Summary: Distributed locks with Redis +License: MIT +URL: https://github.com/glasslion/redlock +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/e1/e1/18cccf47bfeefa66dd7cd90b106c5e72922cd9577b0aa8518847836d0391/redlock-1.2.0.tar.gz +BuildArch: noarch + + +%description +|Build Status| +This library implements the RedLock algorithm introduced by +`@antirez <http://antirez.com/>`__ +Yet another ... +~~~~~~~~~~~~~~~ +There are already a few redis based lock implementations in the Python +world, e.g. `retools <https://github.com/bbangert/retools>`__, +`redis-lock <https://pypi.python.org/pypi/redis-lock/0.2.0>`__. +However, these libraries can only work with *single-master* redis +server. When the Redis master goes down, your application has to face a +single point of failure . We can't rely on the master-slave replication, +because Redis replication is asynchronous. + This is an obvious race condition with the master-slave replication + model : + #. Client A acquires the lock into the master. + #. The master crashes before the write to the key is transmitted to + the slave. + #. The slave gets promoted to master. + #. Client B acquires the lock to the same resource A already holds a + lock for. SAFETY VIOLATION! +A quick introduction to the RedLock algorithm +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +To resolve this problem, the Redlock algorithm assume we have ``N`` +Redis masters. These nodes are totally independent (no replications). In +order to acquire the lock, the client will try to acquire the lock in +all the N instances sequentially. If and only if the client was able to +acquire the lock in the majority (``(N+1)/2``)of the instances, the lock +is considered to be acquired. +The detailed description of the RedLock algorithm can be found in the +Redis documentation: `Distributed locks with +Redis <http://redis.io/topics/distlock>`__. +APIs +~~~~ +The ``redlock.RedLock`` class shares a similar API with the +``threading.Lock`` class in the Python Standard Library. +Basic Usage +^^^^^^^^^^^ + from redlock import RedLock + # By default, if no redis connection details are + # provided, RedLock uses redis://127.0.0.1:6379/0 + lock = RedLock("distributed_lock") + lock.acquire() + do_something() + lock.release() +With Statement / Context Manager +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +As with ``threading.Lock``, ``redlock.RedLock`` objects are context +managers thus support the `With +Statement <https://docs.python.org/2/reference/datamodel.html#context-managers>`__. +This way is more pythonic and recommended. + from redlock import RedLock + with RedLock("distributed_lock"): + do_something() +Specify multiple Redis nodes +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + from redlock import RedLock + with RedLock("distributed_lock", + connection_details=[ + {'host': 'xxx.xxx.xxx.xxx', 'port': 6379, 'db': 0}, + {'host': 'xxx.xxx.xxx.xxx', 'port': 6379, 'db': 0}, + {'host': 'xxx.xxx.xxx.xxx', 'port': 6379, 'db': 0}, + {'host': 'xxx.xxx.xxx.xxx', 'port': 6379, 'db': 0}, + ] + ): + do_something() +| The ``connection_details`` parameter expects a list of keyword +arguments for initializing Redis clients. +| Other acceptable Redis client arguments can be found on the `redis-py +doc <http://redis-py.readthedocs.org/en/latest/#redis.StrictRedis>`__. +Reuse Redis clients with the RedLockFactory +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Usually the connection details of the Redis nodes are fixed. +``RedLockFactory`` can help reuse them, create multiple RedLocks but +only initialize the clients once. + from redlock import RedLockFactory + factory = RedLockFactory( + connection_details=[ + {'host': 'xxx.xxx.xxx.xxx'}, + {'host': 'xxx.xxx.xxx.xxx'}, + {'host': 'xxx.xxx.xxx.xxx'}, + {'host': 'xxx.xxx.xxx.xxx'}, + ]) + with factory.create_lock("distributed_lock"): + do_something() + with factory.create_lock("another_lock"): + do_something() + +%package -n python3-redlock +Summary: Distributed locks with Redis +Provides: python-redlock +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-redlock +|Build Status| +This library implements the RedLock algorithm introduced by +`@antirez <http://antirez.com/>`__ +Yet another ... +~~~~~~~~~~~~~~~ +There are already a few redis based lock implementations in the Python +world, e.g. `retools <https://github.com/bbangert/retools>`__, +`redis-lock <https://pypi.python.org/pypi/redis-lock/0.2.0>`__. +However, these libraries can only work with *single-master* redis +server. When the Redis master goes down, your application has to face a +single point of failure . We can't rely on the master-slave replication, +because Redis replication is asynchronous. + This is an obvious race condition with the master-slave replication + model : + #. Client A acquires the lock into the master. + #. The master crashes before the write to the key is transmitted to + the slave. + #. The slave gets promoted to master. + #. Client B acquires the lock to the same resource A already holds a + lock for. SAFETY VIOLATION! +A quick introduction to the RedLock algorithm +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +To resolve this problem, the Redlock algorithm assume we have ``N`` +Redis masters. These nodes are totally independent (no replications). In +order to acquire the lock, the client will try to acquire the lock in +all the N instances sequentially. If and only if the client was able to +acquire the lock in the majority (``(N+1)/2``)of the instances, the lock +is considered to be acquired. +The detailed description of the RedLock algorithm can be found in the +Redis documentation: `Distributed locks with +Redis <http://redis.io/topics/distlock>`__. +APIs +~~~~ +The ``redlock.RedLock`` class shares a similar API with the +``threading.Lock`` class in the Python Standard Library. +Basic Usage +^^^^^^^^^^^ + from redlock import RedLock + # By default, if no redis connection details are + # provided, RedLock uses redis://127.0.0.1:6379/0 + lock = RedLock("distributed_lock") + lock.acquire() + do_something() + lock.release() +With Statement / Context Manager +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +As with ``threading.Lock``, ``redlock.RedLock`` objects are context +managers thus support the `With +Statement <https://docs.python.org/2/reference/datamodel.html#context-managers>`__. +This way is more pythonic and recommended. + from redlock import RedLock + with RedLock("distributed_lock"): + do_something() +Specify multiple Redis nodes +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + from redlock import RedLock + with RedLock("distributed_lock", + connection_details=[ + {'host': 'xxx.xxx.xxx.xxx', 'port': 6379, 'db': 0}, + {'host': 'xxx.xxx.xxx.xxx', 'port': 6379, 'db': 0}, + {'host': 'xxx.xxx.xxx.xxx', 'port': 6379, 'db': 0}, + {'host': 'xxx.xxx.xxx.xxx', 'port': 6379, 'db': 0}, + ] + ): + do_something() +| The ``connection_details`` parameter expects a list of keyword +arguments for initializing Redis clients. +| Other acceptable Redis client arguments can be found on the `redis-py +doc <http://redis-py.readthedocs.org/en/latest/#redis.StrictRedis>`__. +Reuse Redis clients with the RedLockFactory +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Usually the connection details of the Redis nodes are fixed. +``RedLockFactory`` can help reuse them, create multiple RedLocks but +only initialize the clients once. + from redlock import RedLockFactory + factory = RedLockFactory( + connection_details=[ + {'host': 'xxx.xxx.xxx.xxx'}, + {'host': 'xxx.xxx.xxx.xxx'}, + {'host': 'xxx.xxx.xxx.xxx'}, + {'host': 'xxx.xxx.xxx.xxx'}, + ]) + with factory.create_lock("distributed_lock"): + do_something() + with factory.create_lock("another_lock"): + do_something() + +%package help +Summary: Development documents and examples for redlock +Provides: python3-redlock-doc +%description help +|Build Status| +This library implements the RedLock algorithm introduced by +`@antirez <http://antirez.com/>`__ +Yet another ... +~~~~~~~~~~~~~~~ +There are already a few redis based lock implementations in the Python +world, e.g. `retools <https://github.com/bbangert/retools>`__, +`redis-lock <https://pypi.python.org/pypi/redis-lock/0.2.0>`__. +However, these libraries can only work with *single-master* redis +server. When the Redis master goes down, your application has to face a +single point of failure . We can't rely on the master-slave replication, +because Redis replication is asynchronous. + This is an obvious race condition with the master-slave replication + model : + #. Client A acquires the lock into the master. + #. The master crashes before the write to the key is transmitted to + the slave. + #. The slave gets promoted to master. + #. Client B acquires the lock to the same resource A already holds a + lock for. SAFETY VIOLATION! +A quick introduction to the RedLock algorithm +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +To resolve this problem, the Redlock algorithm assume we have ``N`` +Redis masters. These nodes are totally independent (no replications). In +order to acquire the lock, the client will try to acquire the lock in +all the N instances sequentially. If and only if the client was able to +acquire the lock in the majority (``(N+1)/2``)of the instances, the lock +is considered to be acquired. +The detailed description of the RedLock algorithm can be found in the +Redis documentation: `Distributed locks with +Redis <http://redis.io/topics/distlock>`__. +APIs +~~~~ +The ``redlock.RedLock`` class shares a similar API with the +``threading.Lock`` class in the Python Standard Library. +Basic Usage +^^^^^^^^^^^ + from redlock import RedLock + # By default, if no redis connection details are + # provided, RedLock uses redis://127.0.0.1:6379/0 + lock = RedLock("distributed_lock") + lock.acquire() + do_something() + lock.release() +With Statement / Context Manager +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +As with ``threading.Lock``, ``redlock.RedLock`` objects are context +managers thus support the `With +Statement <https://docs.python.org/2/reference/datamodel.html#context-managers>`__. +This way is more pythonic and recommended. + from redlock import RedLock + with RedLock("distributed_lock"): + do_something() +Specify multiple Redis nodes +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + from redlock import RedLock + with RedLock("distributed_lock", + connection_details=[ + {'host': 'xxx.xxx.xxx.xxx', 'port': 6379, 'db': 0}, + {'host': 'xxx.xxx.xxx.xxx', 'port': 6379, 'db': 0}, + {'host': 'xxx.xxx.xxx.xxx', 'port': 6379, 'db': 0}, + {'host': 'xxx.xxx.xxx.xxx', 'port': 6379, 'db': 0}, + ] + ): + do_something() +| The ``connection_details`` parameter expects a list of keyword +arguments for initializing Redis clients. +| Other acceptable Redis client arguments can be found on the `redis-py +doc <http://redis-py.readthedocs.org/en/latest/#redis.StrictRedis>`__. +Reuse Redis clients with the RedLockFactory +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Usually the connection details of the Redis nodes are fixed. +``RedLockFactory`` can help reuse them, create multiple RedLocks but +only initialize the clients once. + from redlock import RedLockFactory + factory = RedLockFactory( + connection_details=[ + {'host': 'xxx.xxx.xxx.xxx'}, + {'host': 'xxx.xxx.xxx.xxx'}, + {'host': 'xxx.xxx.xxx.xxx'}, + {'host': 'xxx.xxx.xxx.xxx'}, + ]) + with factory.create_lock("distributed_lock"): + do_something() + with factory.create_lock("another_lock"): + do_something() + +%prep +%autosetup -n redlock-1.2.0 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-redlock -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Tue Apr 11 2023 Python_Bot <Python_Bot@openeuler.org> - 1.2.0-1 +- Package Spec generated |
