阻止重复帧

This commit is contained in:
Guoqs
2024-10-28 14:45:15 +08:00
parent 6bb08fde40
commit 2eb4999038

View File

@@ -22,6 +22,8 @@ public abstract class AbstractYkcHandler implements InitializingBean {
@Autowired
private RedisCache redisCache;
private static final String REQUEST_PREFIX = "Request_";
/**
* 执行逻辑
* 有应答
@@ -96,7 +98,7 @@ public abstract class AbstractYkcHandler implements InitializingBean {
String frameTypeStr = YKCUtils.frameType2Str(ykcDataProtocol.getFrameType());
// 获取channelId
String channelId = ctx.channel().id().asShortText();
String redisKey = "Request_" + channelId + "_" + frameTypeStr;
String redisKey = REQUEST_PREFIX + channelId + "_" + frameTypeStr;
Boolean result = redisCache.setnx(redisKey, ykcDataProtocol.getHEXString(), 30);
// result返回false说明没有设置成功就是说已经有相同请求了所以返回true重复
return !result;