From e663e707c3b66b13da06eaebc41e33813ed8d811 Mon Sep 17 00:00:00 2001 From: Furkan Bilgin Date: Tue, 24 Dec 2024 13:26:32 +0300 Subject: [PATCH] fix: update item key construction in Redis store to handle tags correctly --- src/enrgdaq/daq/jobs/store/redis.py | 5 ++--- src/tests/test_redis.py | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/enrgdaq/daq/jobs/store/redis.py b/src/enrgdaq/daq/jobs/store/redis.py index 0b9a19a..25f7128 100644 --- a/src/enrgdaq/daq/jobs/store/redis.py +++ b/src/enrgdaq/daq/jobs/store/redis.py @@ -97,9 +97,8 @@ def store_loop(self): # Append item to key in redis for i, item in enumerate(msg.data.items()): key, values = item - item_key = f"{msg.store_config.key}.{key}" - if msg.tag is not None: - item_key = f"{msg.tag}.{item_key}" + tag = "" if msg.tag is None else f".{msg.tag}" + item_key = f"{msg.store_config.key}{tag}.{key}" if msg.store_config.use_timeseries: # Use Redis TimeSeries if requested diff --git a/src/tests/test_redis.py b/src/tests/test_redis.py index 1071732..626b815 100644 --- a/src/tests/test_redis.py +++ b/src/tests/test_redis.py @@ -87,7 +87,7 @@ def test_store_loop(self): "header1": ["row1_col1", "row2_col1"], "header2": ["row1_col2", "row2_col2"], }, - tag="prefix", + tag="tag", ), RedisWriteQueueItem( store_config=DAQJobStoreConfigRedis( @@ -100,7 +100,7 @@ def test_store_loop(self): "header1": ["row1_col1", "row2_col1"], "header2": ["row1_col2", "row2_col2"], }, - tag="prefix", + tag="tag", ), ] ) @@ -117,29 +117,29 @@ def test_store_loop(self): ) self.store._connection.rpush.assert_any_call( - "prefix.test_key_no_expiration.header1", "row1_col1", "row2_col1" + "test_key_no_expiration.tag.header1", "row1_col1", "row2_col1" ) self.store._connection.rpush.assert_any_call( - "prefix.test_key_no_expiration.header2", "row1_col2", "row2_col2" + "test_key_no_expiration.tag.header2", "row1_col2", "row2_col2" ) self.store._ts.madd.assert_any_call( [ - ("prefix.test_key_timeseries.header1", unix_ms, "row1_col1"), - ("prefix.test_key_timeseries.header1", unix_ms + 1, "row2_col1"), + ("test_key_timeseries.tag.header1", unix_ms, "row1_col1"), + ("test_key_timeseries.tag.header1", unix_ms + 1, "row2_col1"), ] ) self.store._ts.create.assert_any_call( - "prefix.test_key_timeseries.header2", + "test_key_timeseries.tag.header2", retention_msecs=int(timedelta(days=1).total_seconds() * 1000), - labels={"key": "test_key_timeseries", "tag": "prefix"}, + labels={"key": "test_key_timeseries", "tag": "tag"}, ) self.store._ts.madd.assert_any_call( [ - ("prefix.test_key_timeseries.header2", unix_ms, "row1_col2"), - ("prefix.test_key_timeseries.header2", unix_ms + 1, "row2_col2"), + ("test_key_timeseries.tag.header2", unix_ms, "row1_col2"), + ("test_key_timeseries.tag.header2", unix_ms + 1, "row2_col2"), ] )