ソースを参照

移动侦测接口使用副本端点读取数据

locky 1 年間 前
コミット
76dd9ed751
2 ファイル変更8 行追加6 行削除
  1. 5 4
      Controller/DetectController.py
  2. 3 2
      Controller/DetectControllerV2.py

+ 5 - 4
Controller/DetectController.py

@@ -45,6 +45,7 @@ class NotificationView(View):
         if not all([channel, n_time]):
             return JsonResponse(status=200, data={'code': 444, 'msg': 'error channel or n_time'})
         redisObj = RedisObject(db=6)
+        redis_r_obj = RedisObject(mode='r', db=6)
         try:
             uid = DevicePushService.decode_uid(etk, uidToken)  # 解密uid
             if len(uid) != 20 and len(uid) != 14:
@@ -61,9 +62,9 @@ class NotificationView(View):
             else:
                 dkey = '{}_{}_flag'.format(uid, channel)
 
-            have_ykey = redisObj.get_data(key=ykey)  # uid_set 数据库缓存
-            have_pkey = redisObj.get_data(key=pkey)  # 一分钟限制key
-            have_dkey = redisObj.get_data(key=dkey)  # 推送类型限制
+            have_ykey = redis_r_obj.get_data(key=ykey)  # uid_set 数据库缓存
+            have_pkey = redis_r_obj.get_data(key=pkey)  # 一分钟限制key
+            have_dkey = redis_r_obj.get_data(key=dkey)  # 推送类型限制
 
             # 一分钟外,推送开启状态
             detect_med_type = 0  # 0推送旧机制 1存库不推送,2推送存库
@@ -74,7 +75,7 @@ class NotificationView(View):
 
             # 数据库读取数据
             if have_ykey:
-                uid_push_list = eval(redisObj.get_data(key=ykey))
+                uid_push_list = eval(redis_r_obj.get_data(key=ykey))
             else:
                 # 从数据库查询出来
                 uid_push_qs = DevicePushService.query_uid_push(uid, event_type)

+ 3 - 2
Controller/DetectControllerV2.py

@@ -61,6 +61,7 @@ class NotificationV2View(View):
         region = int(region)
         event_type = int(event_type)
         redis_obj = RedisObject()
+        redis_r_obj = RedisObject(mode='r')
         try:
             uid = DevicePushService.decode_uid(etk, uidToken)
             if len(uid) != 20 and len(uid) != 14:
@@ -74,8 +75,8 @@ class NotificationV2View(View):
                 push_interval = '{}_{}_flag'.format(uid, channel)
 
             req_limiting = '{}_{}_{}_ptl'.format(uid, channel, event_type)
-            cache_req_limiting = redis_obj.get_data(key=req_limiting)  # 获取请求限流缓存数据
-            cache_app_push = redis_obj.get_data(key=push_interval)  # 获取APP推送消息时间间隔缓存数据
+            cache_req_limiting = redis_r_obj.get_data(key=req_limiting)  # 获取请求限流缓存数据
+            cache_app_push = redis_r_obj.get_data(key=push_interval)  # 获取APP推送消息时间间隔缓存数据
             if event_type not in [606, 607]:
                 if cache_req_limiting:  # 限流存在则直接返回
                     return JsonResponse(status=200, data={'code': 0, 'msg': 'Push again in one minute'})