Explorar o código

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

locky %!s(int64=3) %!d(string=hai) anos
pai
achega
041dc0ab62
Modificáronse 1 ficheiros con 8 adicións e 0 borrados
  1. 8 0
      Controller/SerialNumberController.py

+ 8 - 0
Controller/SerialNumberController.py

@@ -150,6 +150,14 @@ class SerialNumberView(View):
 
 
         if serial_number[9:10]:
         if serial_number[9:10]:
             p2p_type = 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:
         try:
             if not country_id:
             if not country_id:
                 # 设备模拟国外环境测试
                 # 设备模拟国外环境测试