Quellcode durchsuchen

redis释放资源

zhangdongming vor 1 Jahr
Ursprung
Commit
60dae2ec36
2 geänderte Dateien mit 5 neuen und 1 gelöschten Zeilen
  1. 3 1
      Controller/DetectController.py
  2. 2 0
      Controller/gatewayController.py

+ 3 - 1
Controller/DetectController.py

@@ -45,6 +45,7 @@ class NotificationView(View):
         uid = request_dict.get('uid', None)
         if not all([channel, n_time]):
             return JsonResponse(status=200, data={'code': 444, 'msg': 'error channel or n_time'})
+        redisObj = RedisObject(db=6)
         try:
             if not uid:
                 uid = DevicePushService.decode_uid(etk, uidToken)  # 解密uid
@@ -60,7 +61,6 @@ class NotificationView(View):
             else:
                 dkey = '{uid}_{channel}_flag'.format(uid=uid, channel=channel)
 
-            redisObj = RedisObject(db=6)
             have_ykey = redisObj.get_data(key=ykey)  # uid_set 数据库缓存
             have_pkey = redisObj.get_data(key=pkey)  # 一分钟限制key
             have_dkey = redisObj.get_data(key=dkey)  # 推送类型限制
@@ -214,6 +214,8 @@ class NotificationView(View):
                 'errMsg': repr(e),
             }
             return JsonResponse(status=200, data=json.dumps(data), safe=False)
+        finally:
+            redisObj.CONN.close()
 
     def is_sys_msg(self, event_type):
         event_type_list = [702, 703, 704]

+ 2 - 0
Controller/gatewayController.py

@@ -346,3 +346,5 @@ class GatewayView(View):
             redis_obj.del_data(event_key)
             LOGGER.info('---插座开关日志推送接口异常--- {}'.format(repr(e)))
             return response.json(500, repr(e))
+        finally:
+            redis_obj.CONN.close()