소스 검색

redis释放资源

zhangdongming 1 년 전
부모
커밋
a6d6a17d7e
2개의 변경된 파일5개의 추가작업 그리고 1개의 파일을 삭제
  1. 3 1
      Controller/DetectController.py
  2. 2 0
      Controller/gatewayController.py

+ 3 - 1
Controller/DetectController.py

@@ -44,6 +44,7 @@ class NotificationView(View):
         is_st = request_dict.get('is_st', 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:
             uid = DevicePushService.decode_uid(etk, uidToken)  # 解密uid
             if len(uid) != 20 and len(uid) != 14:
@@ -58,7 +59,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)  # 推送类型限制
@@ -213,6 +213,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

@@ -440,3 +440,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()