Skip to content

Commit

Permalink
[#11497] Improve atomicity and performance of Redis call in ActiveThread
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Oct 14, 2024
1 parent 9a3454c commit ef62288
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ public void publish(CollectorState state) {

private void publishBytes(byte[] bytes) {
String value = BytesUtils.toString(bytes);
this.redisTemplate.opsForValue().set(this.key, value);
this.redisTemplate.expire(this.key, this.ttl);
this.redisTemplate.opsForValue().set(this.key, value, this.ttl);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ public void test() throws IOException {

doReturn(TEST_RESULT.getBytes()).when(serde).serializeToByteArray(eq(state));
doReturn(redisValueOperations).when(redisTemplate).opsForValue();
doReturn(true).when(redisTemplate).expire(eq(TEST_KEY), any());
doNothing().when(redisValueOperations).set(eq(TEST_KEY), eq(TEST_RESULT));
doNothing().when(redisValueOperations).set(eq(TEST_KEY), eq(TEST_RESULT), any());

RedisCollectorStatePublisherService service = new RedisCollectorStatePublisherService(
redisTemplate,
Expand All @@ -63,8 +62,7 @@ public void test() throws IOException {
);
service.publish(state);

verify(redisTemplate).expire(eq(TEST_KEY), any());
verify(redisValueOperations).set(eq(TEST_KEY), eq(TEST_RESULT));
verify(redisValueOperations).set(eq(TEST_KEY), eq(TEST_RESULT), any());
}

}

0 comments on commit ef62288

Please sign in to comment.