Skip to content

Commit

Permalink
[pinpoint-apm#11497] Improve atomicity and performance of Redis call …
Browse files Browse the repository at this point in the history
…in ActiveThread
  • Loading branch information
emeroad committed Oct 14, 2024
1 parent 9a3454c commit 5ab421a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ class RedisKVPubChannel implements PubChannel {

@Override
public void publish(byte[] content) {
this.template.opsForValue().set(this.key, BytesUtils.toString(content));
this.template.expire(this.key, expireMs, TimeUnit.MILLISECONDS);
this.template.opsForValue().set(this.key, BytesUtils.toString(content), expireMs, TimeUnit.MILLISECONDS);
}

}

0 comments on commit 5ab421a

Please sign in to comment.