Administrator
2023-08-07 2a7e23ae3e01e05f2e01f179764e1c9cef71ac70
redis批量提交数据
4个文件已修改
45 ■■■■ 已修改文件
code_attribute/code_volumn_manager.py 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
db/redis_manager.py 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/huaxin/huaxin_target_codes_manager.py 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
third_data/code_plate_key_manager.py 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
code_attribute/code_volumn_manager.py
@@ -21,7 +21,8 @@
    global_util.max60_volumn[code] = (max60, max60_day)
    global_util.yesterday_volumn[code] = yesterday
    try:
        RedisUtils.setex(redis, "volumn_max60-{}".format(code), tool.get_expire(), json.dumps((max60, max60_day)), auto_free=False)
        RedisUtils.setex(redis, "volumn_max60-{}".format(code), tool.get_expire(), json.dumps((max60, max60_day)),
                         auto_free=False)
        RedisUtils.setex(redis, "volumn_yes-{}".format(code), tool.get_expire(), yesterday, auto_free=False)
    finally:
        RedisUtils.realse(redis)
@@ -57,7 +58,22 @@
    if code in __today_volumn_cache and volumn - __today_volumn_cache[code] < 100000:
        return
    __today_volumn_cache[code] = volumn
    RedisUtils.setex( __redis_manager.getRedis(), "volumn_today-{}".format(code), tool.get_expire(), volumn)
    RedisUtils.setex(__redis_manager.getRedis(), "volumn_today-{}".format(code), tool.get_expire(), volumn)
# datas:[(code, volumn)]
def set_today_volumns(datas):
    pipe = __redis_manager.getRedis().pipeline()
    for d in datas:
        code, volumn = d
        logger_day_volumn.info("code:{} volumn:{}".format(code, volumn))
        global_util.today_volumn[code] = volumn
        # 有1000手的变化才保存
        if code in __today_volumn_cache and volumn - __today_volumn_cache[code] < 100000:
            continue
        __today_volumn_cache[code] = volumn
        RedisUtils.setex(pipe, "volumn_today-{}".format(code), tool.get_expire(), volumn)
    pipe.execute()
# 获取今日量
db/redis_manager.py
@@ -2,11 +2,13 @@
redis管理器
"""
import time
from threading import Thread
import redis
import constant
from log_module.log import logger_redis_debug
from utils import tool
config = constant.REDIS_CONFIG
@@ -87,6 +89,7 @@
    @classmethod
    def setex(cls, redis_, key, expire, val, auto_free=True):
        time.sleep(1)
        __start_time = time.time()
        try:
            return redis_.setex(key, expire, val)
@@ -95,6 +98,10 @@
            if auto_free:
                # redis_.connection_pool.disconnect()
                pass
    @classmethod
    def setex_async(cls, redis_, key, expire, val, auto_free=True):
        Thread(target=lambda: cls.setex(redis_, key, expire, val, auto_free)).start()
    @classmethod
    def setnx(cls, redis_, key, val, auto_free=True):
@@ -215,8 +222,7 @@
if __name__ == "__main__":
    redisManager = RedisManager(0)
    for i in range(0, 50):
        print(i)
        redis = redisManager.getRedis()
        redis
    time1 = time.time()
    RedisUtils.setex_async(RedisManager(0).getRedis(), "test123123", tool.get_expire(), "123213")
    print(time.time() - time1)
    input()
l2/huaxin/huaxin_target_codes_manager.py
@@ -67,6 +67,7 @@
        yesterday_codes = kpl_data_manager.get_yesterday_limit_up_codes()
        # 订阅的代码
        flist = []
        temp_volumns = []
        for d in datas:
            code = d[0]
            # 格式 (代码,现价,涨幅,量,更新时间)
@@ -88,7 +89,8 @@
                    ZYLTGBUtil.save(code, zylt // 10000, 1)
                    global_util.zyltgb_map[code] = int(zylt)
            # 保存今日实时量
            code_volumn_manager.set_today_volumn(code, d[3])
            temp_volumns.append((code, d[3]))
            zyltgb = 0
            if code in global_util.zyltgb_map:
@@ -97,6 +99,7 @@
            fitem = {"code": code, "price": d[1], "volume": d[3] // (10000 * 100), "volumeUnit": 1, "time": "00:00:00",
                     "zyltgb": zyltgb // 10000, "zyltgbUnit": 1}
            flist.append(fitem)
        code_volumn_manager.set_today_volumns(temp_volumns)
        print("首板代码数量", len(flist))
        try:
            tick_datas = first_target_code_data_processor.process_first_codes_datas(flist)
third_data/code_plate_key_manager.py
@@ -417,9 +417,9 @@
        can_buy_blocks = []
        for block in keys:
            is_top_8_record, top_8_record = kpl_block_util.is_record_top_block(code, block, limit_up_record_datas,
                                                                               yesterday_current_limit_up_codes, 20)
                                                                               yesterday_current_limit_up_codes, 50)
            is_top_4_current, top_4_current = kpl_block_util.is_current_top_block(code, block, current_limit_up_datas,
                                                                                  yesterday_current_limit_up_codes, 10)
                                                                                  yesterday_current_limit_up_codes, 50)
            is_top_4 = is_top_8_record and is_top_4_current
            msg_list.append(f"\n实时top10(涨停数量:{len(current_limit_up_datas)})")
            msg_list.append(f"历史top20(涨停数量:{top_8_record})")