From caee9ee5f819c9b86fa8e2e0fd9d77a2ba79dc7f Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期三, 02 八月 2023 14:10:41 +0800
Subject: [PATCH] redis缓存加入内存缓存

---
 l2/huaxin/huaxin_target_codes_manager.py |   23 ++++++++++++-----------
 l2/l2_data_manager_new.py                |    4 +---
 2 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/l2/huaxin/huaxin_target_codes_manager.py b/l2/huaxin/huaxin_target_codes_manager.py
index b23366c..1a1e3cb 100644
--- a/l2/huaxin/huaxin_target_codes_manager.py
+++ b/l2/huaxin/huaxin_target_codes_manager.py
@@ -3,6 +3,7 @@
 """
 import json
 import logging
+import queue
 import socket
 import time
 
@@ -14,12 +15,14 @@
 from utils import tool, global_util, socket_util
 
 redisManager = redis_manager.RedisManager(4)
+l2_codes_queue = queue.Queue()
 
 
 # 鍗庨懌Level2璁㈤槄浠g爜绠$悊
 class HuaXinL2SubscriptCodesManager:
     __L2_CODE_KEY = "huaxin_l2_code_list"
     __SUBSCRIPT_KEY = "huaxin_subscript_codes"
+    __subscript_codes = []
 
     @classmethod
     def __get_redis(cls):
@@ -27,31 +30,29 @@
 
     @classmethod
     def clear(cls):
-        cls.__get_redis().delete(cls.__L2_CODE_KEY)
+        # cls.__get_redis().delete(cls.__L2_CODE_KEY)
+        l2_codes_queue.clear()
 
     @classmethod
     def push(cls, datas):
-        cls.__get_redis().lpush(cls.__L2_CODE_KEY, json.dumps((int(time.time()), datas)))
+        l2_codes_queue.put_nowait((int(time.time()), datas))
+        # cls.__get_redis().lpush(cls.__L2_CODE_KEY, json.dumps())
 
     @classmethod
     def pop(cls):
-        val = cls.__get_redis().lpop(cls.__L2_CODE_KEY)
-        if val:
-            return json.loads(val)
-        return val
+        return l2_codes_queue.get()
+        # val = cls.__get_redis().lpop(cls.__L2_CODE_KEY)
 
     # 璁剧疆璁㈤槄浠g爜
     @classmethod
     def save_subscript_codes(cls, codes):
-        cls.__get_redis().setex(cls.__SUBSCRIPT_KEY, tool.get_expire(), json.dumps(codes))
+        cls.__subscript_codes = codes
+        # cls.__get_redis().setex(cls.__SUBSCRIPT_KEY, tool.get_expire(), json.dumps(codes))
 
     # 鑾峰彇璁㈤槄鐨勪唬鐮�
     @classmethod
     def get_subscript_codes(cls):
-        val = cls.__get_redis().get(cls.__SUBSCRIPT_KEY)
-        if not val:
-            return []
-        return json.loads(val)
+        return cls.__subscript_codes
 
 
 # 鏍规嵁鍗庨懌L2閫夊嚭鐩爣浠g爜
diff --git a/l2/l2_data_manager_new.py b/l2/l2_data_manager_new.py
index c5d4f48..bfc7387 100644
--- a/l2/l2_data_manager_new.py
+++ b/l2/l2_data_manager_new.py
@@ -804,9 +804,7 @@
                 for i in range(trade_index + 1, total_data[-1]["index"] + 1):
                     if L2DataUtil.is_limit_up_price_buy(total_data[i]["val"]):
                         left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count(code,
-                                                                                                              total_data[
-                                                                                                                  i][
-                                                                                                                  "index"],
+                                                                                                              total_data[i]["index"],
                                                                                                               total_data,
                                                                                                               num_operate_map)
                         if left_count > 0:

--
Gitblit v1.8.0