Commit 5d54f74a authored by BO ZHANG's avatar BO ZHANG 🏀
Browse files

update Redis and tests

parent b0981e72
...@@ -5,13 +5,25 @@ import os ...@@ -5,13 +5,25 @@ import os
redis_config_path = os.path.join(os.path.dirname(__file__), "redis_config.toml") redis_config_path = os.path.join(os.path.dirname(__file__), "redis_config.toml")
REDIS_CONFIG = toml.load(redis_config_path) REDIS_CONFIG = toml.load(redis_config_path)
REDIS_QNAME = "csst_data_list"
class Redis(redis.Redis): class Redis(redis.Redis):
def __init__(self, **kwargs): def __init__(self, location="naoc"):
super().__init__(**kwargs) if location not in REDIS_CONFIG.keys():
self.name = REDIS_QNAME 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): def push(self, msg):
self.lpush(self.name, msg) self.lpush(self.name, msg)
...@@ -20,18 +32,10 @@ class Redis(redis.Redis): ...@@ -20,18 +32,10 @@ class Redis(redis.Redis):
return self.rpop(self.name) return self.rpop(self.name)
def get_all(self): def get_all(self):
return self.lrange(self.name, 0, -1) return self.lrange(self.qname, 0, -1)
def get_redis(location="naoc"):
print("Available redis locations: ", list(REDIS_CONFIG.keys()))
if location not in REDIS_CONFIG.keys():
raise ValueError(f"Unknown redis location: {location}")
return Redis(**REDIS_CONFIG[location])
# msgs = r.lrange(name, 0, -1) # msgs = r.lrange(name, 0, -1)
#
# for chipid in range(6, 26): # for chipid in range(6, 26):
# this_msg = gen_msg( # this_msg = gen_msg(
# dag_id="csst-msc-l1-mbi", obsid="11009101682009", chipid=f"{chipid:02d}" # dag_id="csst-msc-l1-mbi", obsid="11009101682009", chipid=f"{chipid:02d}"
...@@ -42,6 +46,5 @@ def get_redis(location="naoc"): ...@@ -42,6 +46,5 @@ def get_redis(location="naoc"):
# msgs = r.lrange(name, 0, -1) # msgs = r.lrange(name, 0, -1)
# print(msgs) # print(msgs)
# #
#
# msgs_later = r.lrange(name, 0, -1) # msgs_later = r.lrange(name, 0, -1)
# print(msgs_later) # print(msgs_later)
from csst_dag import get_redis from csst_dag.redis import Redis
def test_redis_naoc(): def test_redis_naoc():
r = get_redis("naoc") r = Redis(location="naoc")
print(r) print(r)
assert r.name == "csst_data_list"
assert len(r.get_all()) == 0 assert len(r.get_all()) == 0
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment