失敗條件
- 已存在獲取失敗
- 超時任務超時失敗
程式碼
import redis_lock
try:
lock_key = "xxxx"
with redis_lock.Lock(redis_client, lock_key, expire=10):
# do something
db_session.commit()
logger.info("ok")
except Exception as e:
logger.error("fail")
db_session.rollback()
finally:
db_session.close()