import redis import toml import os redis_config_path = os.path.join(os.path.dirname(__file__), "redis_config.toml") REDIS_CONFIG = toml.load(redis_config_path) class Redis(redis.Redis): def __init__(self, location="naoc"): if location not in REDIS_CONFIG.keys(): print("Available redis locations: ", list(REDIS_CONFIG.keys())) raise ValueError(f"Unknown redis location: {location}") super().__init__( host=REDIS_CONFIG[location]["host"], port=REDIS_CONFIG[location]["port"], db=REDIS_CONFIG[location]["db"], password=REDIS_CONFIG[location]["password"], ) self.qname = password = REDIS_CONFIG[location]["qname"] self.config = REDIS_CONFIG[location] print("Setting redis config:") for k, v in self.config.items(): print(f" - {k}: {v}") def push(self, msg): self.lpush(self.qname, msg) def pop(self): return self.rpop(self.qname) def get_all(self): return self.lrange(self.qname, 0, -1) # msgs = r.lrange(name, 0, -1) # for chipid in range(6, 26): # this_msg = gen_msg( # dag_id="csst-msc-l1-mbi", obsid="11009101682009", chipid=f"{chipid:02d}" # ) # print(this_msg) # r.lpush(name, this_msg) # # msgs = r.lrange(name, 0, -1) # print(msgs) # # msgs_later = r.lrange(name, 0, -1) # print(msgs_later)