liqian 3 år sedan
förälder
incheckning
bac6a5c879
3 ändrade filer med 14 tillägg och 13 borttagningar
  1. 2 2
      config.py
  2. 11 0
      db_helper.py
  3. 1 11
      video_recall.py

+ 2 - 2
config.py

@@ -167,6 +167,6 @@ class ProductionConfig(BaseConfig):
 
 def set_config():
     # return DevelopmentConfig()
-    # return TestConfig()
+    return TestConfig()
     # return PreProductionConfig()
-    return ProductionConfig()
+    # return ProductionConfig()

+ 11 - 0
db_helper.py

@@ -230,6 +230,17 @@ class RedisHelper(object):
         conn.incr(name=key_name, amount=amount)
         conn.expire(key_name, int(expire_time))
 
+    def setnx_key(self, key_name, value, expire_time=5*60):
+        """
+        当key不存在时,将value塞入key中,key存在时不做操作
+        :param key_name: key
+        :param value: value
+        :return: 过期时间,单位:s,默认5分钟 type-int
+        """
+        conn = self.connect()
+        conn.setnx(name=key_name, value=value)
+        conn.expire(name=key_name, time=int(expire_time))
+
 
 #hologres_info = config_.HOLOGRES_INFO
 #conn = psycopg2.connect(**hologres_info)

+ 1 - 11
video_recall.py

@@ -221,17 +221,7 @@ class PoolRecall(object):
                 check_result.append(item)
                 # 将分发数更新到本地记录
                 key_name = '{}{}.{}'.format(config_.LOCAL_DISTRIBUTE_COUNT_PREFIX, item[0], item[1])
-                redis_helper.incr_key(key_name=key_name, amount=remain_count, expire_time=5 * 60)
-
-                # # 判断本地分发数
-                # cur_count = get_videos_local_distribute_count(video_id=item[0], flow_pool=item[1])
-                # # 无记录 或 cur_count > 0
-                # if cur_count is None or cur_count > 0:
-                #     check_result.append(item)
-                # # cur_count <= 0,从流量召回池移除
-                # else:
-                #     value = '{}-{}'.format(item[0], item[1])
-                #     self.redis_helper.remove_value_from_zset(key_name=flow_pool_key, value=value)
+                redis_helper.setnx_key(key_name=key_name, value=remain_count, expire_time=5 * 60)
             else:
                 # viewCount <= 0
                 # 从流量召回池移除