第一次提交:小程序前端最新版本
This commit is contained in:
18
utils/redis_lock.py
Normal file
18
utils/redis_lock.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import redis
|
||||
from django.conf import settings
|
||||
|
||||
redis_client = redis.Redis(
|
||||
host=settings.REDIS_HOST,
|
||||
port=settings.REDIS_PORT,
|
||||
password=settings.REDIS_PASSWORD,
|
||||
db=2,
|
||||
decode_responses=True
|
||||
)
|
||||
|
||||
def acquire_lock(lock_key, timeout=10):
|
||||
"""获取锁,返回是否成功"""
|
||||
return redis_client.set(lock_key, '1', nx=True, ex=timeout)
|
||||
|
||||
def release_lock(lock_key):
|
||||
"""释放锁"""
|
||||
redis_client.delete(lock_key)
|
||||
Reference in New Issue
Block a user