| | |
| | | """ |
| | | |
| | | # 大单管理 |
| | | from db import redis_manager |
| | | from db import redis_manager_delegate as redis_manager |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from utils import tool |
| | | |
| | | __redisManager = redis_manager.RedisManager(0) |
| | | __db = 0 |
| | | __redisManager = redis_manager.RedisManager(__db) |
| | | |
| | | |
| | | # 是否为大单 |
| | | def is_big_num(val): |
| | | if int(val["num"]) >= 8000 or int(val["num"]) * float(val["price"]) >= 30000: |
| | | if int(val["num"]) >= 8999 or int(val["num"]) * float(val["price"]) >= 29900: |
| | | return True |
| | | else: |
| | | return False |
| | | |
| | | |
| | | __big_money_cache = {} |
| | | |
| | | |
| | | def add_num(code, num): |
| | | redis = __redisManager.getRedis() |
| | | redis.incrby("big_money-{}".format(code), num) |
| | | if code not in __big_money_cache: |
| | | __big_money_cache[code] = 0 |
| | | __big_money_cache[code] += num |
| | | RedisUtils.incrby_async(__db, "big_money-{}".format(code), num) |
| | | |
| | | |
| | | # 设置过期时间 |
| | | def expire(code): |
| | | redis = __redisManager.getRedis() |
| | | redis.expire("big_money-{}".format(code), tool.get_expire()) |
| | | RedisUtils.expire(__redisManager.getRedis(), "big_money-{}".format(code), tool.get_expire()) |
| | | |
| | | |
| | | def reset(code): |
| | | redis = __redisManager.getRedis() |
| | | redis.set("big_money-{}".format(code), 0) |
| | | __big_money_cache[code] = 0 |
| | | RedisUtils.set(__redisManager.getRedis(), "big_money-{}".format(code), 0) |
| | | |
| | | |
| | | def get_num(code): |
| | | redis = __redisManager.getRedis() |
| | | num = redis.get("big_money-{}".format(code)) |
| | | num = RedisUtils.get(__redisManager.getRedis(), "big_money-{}".format(code)) |
| | | if num is None: |
| | | return 0 |
| | | return round(int(num) / 1000 / 4) |
| | | |
| | | |
| | | def get_num_cache(code): |
| | | if code in __big_money_cache: |
| | | return __big_money_cache[code] |
| | | num = get_num(code) |
| | | __big_money_cache[code] = num |
| | | return num |
| | | |
| | | |
| | | def reset_all(): |
| | | redis = __redisManager.getRedis() |
| | | keys = redis.keys("big_money-*") |
| | | for k in keys: |
| | | redis.setex(k, tool.get_expire(), 0) |
| | | try: |
| | | keys = RedisUtils.keys(redis, "big_money-*", auto_free=False) |
| | | for k in keys: |
| | | RedisUtils.setex(redis, k, tool.get_expire(), 0, auto_free=False) |
| | | finally: |
| | | RedisUtils.realse(redis) |
| | | |
| | | |
| | | if __name__ == "__main__": |