def _get_lock(lock_name, expiration):
"""
Creates a new redis LuaLock
Args:
lock_name (str): The name of the lock
expiration (datetime.datetime): The expiration datetime
Returns:
redis.lock.LuaLock: a redis lua-based lock
"""
timeout = int((expiration - now_in_utc()).total_seconds())
# this is a StrictRedis instance, we need this for the script installation that LuaLock uses
redis = caches['redis'].client.get_client()
# don't block acquiring the lock, the task will need to try again later
return LuaLock(redis, lock_name, timeout=timeout, blocking=False, thread_local=False)
评论列表
文章目录