浏览代码

v2 redis释放资源

zhangdongming 1 年之前
父节点
当前提交
a9176ccb1a
共有 1 个文件被更改,包括 4 次插入1 次删除
  1. 4 1
      Controller/DetectControllerV2.py

+ 4 - 1
Controller/DetectControllerV2.py

@@ -69,6 +69,7 @@ class NotificationV2View(View):
         if time_token:
             if not CommonService.check_time_stamp_token(time_token, n_time):
                 return JsonResponse(status=200, data={'code': 13, 'msg': 'Timestamp token verification failed'})
+        redisObj = RedisObject(db=6)
         try:
             is_st = int(is_st)
             region = int(region)
@@ -85,7 +86,7 @@ class NotificationV2View(View):
                     .format(uid=uid, channel=channel, event_type=event_type)
             else:
                 push_interval = '{uid}_{channel}_flag'.format(uid=uid, channel=channel)
-            redisObj = RedisObject(db=6)
+
             cache_req_limiting = redisObj.get_data(key=req_limiting)  # 获取请求限流缓存数据
             cache_app_push = redisObj.get_data(key=push_interval)  # 获取APP推送消息时间间隔缓存数据
             logger.info('消息推送- 限流key: {}, 推送间隔key: {}'.
@@ -149,6 +150,8 @@ class NotificationV2View(View):
                 'errMsg': repr(e),
             }
             return JsonResponse(status=200, data=json.dumps(data), safe=False)
+        finally:
+            redisObj.CONN.close()
 
     @classmethod
     def get_combo_msg_type(cls, ai_type, event_type):