###一个用redis实现的分布式锁,含有retry和timetout的功能。
* 用with做锁的逻辑语句
* timeout避免了避免了任务出现异常,没有做delete操作
* 对于长时间的业务,增加retry重试锁的次数
更新:
1. 增加了ask_lock接口
```
#coding:utf-8
#my blog: http://xiaorui.cc
from __future__ import with_statement
import redis
import time
from redis_netlock import dist_lock
client = redis.Redis(connection_pool=redis.BlockingConnectionPool(max_connections=15, host='localhost', port=6379))
with dist_lock('test', client):
time.sleep(10)
print 'welcome to my blog, http://xiaorui.cc'
```
#####同时运行test.py and test2.py
python test.py
```
root@li568-252 redis_netlock]# python test.py
welcome to my blog, http://xiaorui.cc
```
python test2.py
```
[root@li568-252 redis_netlock]# python test2.py
Sleeipng for 0.404031367603
Sleeipng for 1.19347232007
Sleeipng for 2.47668271021
Sleeipng for 4.55280708824
hello
```
* 用with做锁的逻辑语句
* timeout避免了避免了任务出现异常,没有做delete操作
* 对于长时间的业务,增加retry重试锁的次数
更新:
1. 增加了ask_lock接口
```
#coding:utf-8
#my blog: http://xiaorui.cc
from __future__ import with_statement
import redis
import time
from redis_netlock import dist_lock
client = redis.Redis(connection_pool=redis.BlockingConnectionPool(max_connections=15, host='localhost', port=6379))
with dist_lock('test', client):
time.sleep(10)
print 'welcome to my blog, http://xiaorui.cc'
```
#####同时运行test.py and test2.py
python test.py
```
root@li568-252 redis_netlock]# python test.py
welcome to my blog, http://xiaorui.cc
```
python test2.py
```
[root@li568-252 redis_netlock]# python test2.py
Sleeipng for 0.404031367603
Sleeipng for 1.19347232007
Sleeipng for 2.47668271021
Sleeipng for 4.55280708824
hello
```
Metadata
Release files for redis_netlock 1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| redis_netlock-1.6.tar.gz | 2.3 kB | Without provenance | Details |
Release files / redis_netlock-1.6.tar.gz
| Download URL | redis_netlock-1.6.tar.gz |
|---|---|
| Size | 2.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
701eff5a2b6971c572e99d01c70a3fc85a8d3b4c59a406dbb3f971779498d347
|
|
BLAKE2b-256 checksum How to use checksums |
fd84a972c587c2e4805b2a5aae10a4a4df21c5e6776f9d815aced163b1c3bd25
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for redis_netlock 1.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.