Skip to content

Commit

Permalink
fix: update item key construction in Redis store to handle tags corre…
Browse files Browse the repository at this point in the history
…ctly
  • Loading branch information
furkan-bilgin committed Dec 24, 2024
1 parent 6c132e8 commit e663e70
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
5 changes: 2 additions & 3 deletions src/enrgdaq/daq/jobs/store/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions src/tests/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -100,7 +100,7 @@ def test_store_loop(self):
"header1": ["row1_col1", "row2_col1"],
"header2": ["row1_col2", "row2_col2"],
},
tag="prefix",
tag="tag",
),
]
)
Expand All @@ -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"),
]
)

Expand Down

0 comments on commit e663e70

Please sign in to comment.