chore: 清理 StreamTrimScheduler 过时 javadoc 与死代码
裁剪逻辑已改用 opsForStream().trim() 精确裁剪,但 javadoc 仍写着
XTRIM ... MAXLEN ~(近似裁剪),且 trimAll() 里残留注释掉的旧
connection.execute("XTRIM", ...) 死代码,二者均与现状矛盾。
- javadoc 改为精确裁剪,并注明 2.3.x 无近似重载故不用 ~
- 删除注释掉的旧 XTRIM 裸命令死代码
- 删除随之失效的 import(RedisCallback、StandardCharsets)
注:旧裸命令报错的真因是 ByteArrayOutput 无法解析 XTRIM 的整数
回复(CommandOutput.set(long) 抛 IllegalStateException),与 ~ 无关。
纯注释/import 清理,逻辑零改动,compile 通过。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -4,10 +4,8 @@ import com.njcn.middle.stream.autoconfig.RedisStreamProperties;
|
||||
import com.njcn.middle.stream.handler.EnhanceStreamConsumerHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.SmartLifecycle;
|
||||
import org.springframework.data.redis.core.RedisCallback;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
@@ -20,7 +18,8 @@ import java.util.concurrent.TimeUnit;
|
||||
* 定时裁剪 stream 长度,防止无界增长。
|
||||
*
|
||||
* <p>按 {@code trim.intervalMs} 周期对每个 handler 的 stream 执行
|
||||
* {@code XTRIM <stream> MAXLEN ~ <maxlen>}({@code ~} 近似裁剪,性能更好)。
|
||||
* {@code XTRIM <stream> MAXLEN <maxlen>}(精确裁剪,经 spring-data 高级 API;
|
||||
* 2.3.x 无近似裁剪重载,故不用 {@code ~})。
|
||||
*
|
||||
* <p>无 handler 时不启动。正确性由 C11 集成测试覆盖。
|
||||
*/
|
||||
@@ -81,11 +80,7 @@ public class StreamTrimScheduler implements SmartLifecycle {
|
||||
long maxlen = props.getTrim().getMaxlen();
|
||||
for (String stream : distinctStreams()) {
|
||||
try {
|
||||
redis.opsForStream().trim(stream,maxlen);
|
||||
// redis.execute((RedisCallback<Object>) connection -> connection.execute("XTRIM",
|
||||
// stream.getBytes(StandardCharsets.UTF_8),
|
||||
// "MAXLEN".getBytes(StandardCharsets.UTF_8),
|
||||
// String.valueOf(maxlen).getBytes(StandardCharsets.UTF_8)));
|
||||
redis.opsForStream().trim(stream, maxlen);
|
||||
} catch (Exception e) {
|
||||
log.warn("[redis-stream] trim failed stream={}", stream, e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user