浏览代码

序列号绑定uid redis加锁防止同一个序列号重复绑定

locky 3 年之前
父节点
当前提交
041dc0ab62
共有 1 个文件被更改,包括 8 次插入0 次删除
  1. 8 0
      Controller/SerialNumberController.py

+ 8 - 0
Controller/SerialNumberController.py

@@ -150,6 +150,14 @@ class SerialNumberView(View):
 
         if serial_number[9:10]:
             p2p_type = serial_number[9:10]
+
+        # redis加锁,防止同一个序列号重复绑定
+        redisObj = RedisObject()
+        isLock = redisObj.CONN.setnx(serial + 'do_attach_uid', 1)
+        redisObj.CONN.expire(serial + 'do_attach_uid', 60)
+        if not isLock:
+            return response.json(5)
+
         try:
             if not country_id:
                 # 设备模拟国外环境测试