Skip to content

Commit

Permalink
fixed:fix the issue of Redis 'SET key value nx ex 10' format parsing …
Browse files Browse the repository at this point in the history
…failure
  • Loading branch information
pingxingshikong committed May 31, 2023
1 parent 2ac5485 commit 24bbb7b
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 12 deletions.
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,17 @@
</dependency>

<!-- SQLite 驱动 -->
<!-- <dependency>-->
<!-- <groupId>org.xerial</groupId>-->
<!-- <artifactId>sqlite-jdbc</artifactId>-->
<!-- <version>3.21.0.1</version>-->
<!-- </dependency>-->
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.21.0.1</version>
<version>3.39.3.0</version>
</dependency>

<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,19 +672,54 @@ public Object send(byte[] cmd, byte[]... args) {
if (Strings.byteToString(cmd).toUpperCase().indexOf("SET") >= 0 || Strings.byteToString(cmd).toUpperCase().equalsIgnoreCase("RESTORE") || Strings.byteToString(cmd).toUpperCase().equalsIgnoreCase("RESTOREREPLACE") || Strings.byteToString(cmd).toUpperCase().equalsIgnoreCase("DEL")) {
cleanData(Strings.byteToString(args[0]));
}


if (isSetNxWithTime(cmd, args)) {
String byte3 = Strings.byteToString(args[3]);
String byte4 = Strings.byteToString(args[4]);
try {
long setExData=Long.parseLong(byte3);
}catch (NumberFormatException e){
byte3="ex";
}

kvPersistence.addKey(EventEntity
.builder()
.key(args[0])
.value(args[1])
.stringKey(Strings.byteToString(args[0]))
.pipeLineCompensatorEnum(PipeLineCompensatorEnum.SET_WITH_TIME)
.dbNum(Long.valueOf(currentDbNum))
.cmd("SET".getBytes())
.ms(Long.parseLong(byte3))
.build());
if("ex".equalsIgnoreCase(byte3)||"nx".equalsIgnoreCase(byte3)||"xx".equalsIgnoreCase(byte3)||"px".equalsIgnoreCase(byte3)){
kvPersistence.addKey(EventEntity
.builder()
.key(args[0])
.value(args[1])
.stringKey(Strings.byteToString(args[0]))
.pipeLineCompensatorEnum(PipeLineCompensatorEnum.SET_WITH_TIME)
.dbNum(Long.valueOf(currentDbNum))
.cmd("SET".getBytes())
.ms(Long.parseLong(byte4))
.build());
}else {
kvPersistence.addKey(EventEntity
.builder()
.key(args[0])
.value(args[1])
.stringKey(Strings.byteToString(args[0]))
.pipeLineCompensatorEnum(PipeLineCompensatorEnum.SET_WITH_TIME)
.dbNum(Long.valueOf(currentDbNum))
.cmd("SET".getBytes())
.ms(Long.parseLong(byte3))
.build());
}

// if (isSetNxWithTime(cmd, args)) {
// String byte3 = Strings.byteToString(args[3]);
//
// kvPersistence.addKey(EventEntity
// .builder()
// .key(args[0])
// .value(args[1])
// .stringKey(Strings.byteToString(args[0]))
// .pipeLineCompensatorEnum(PipeLineCompensatorEnum.SET_WITH_TIME)
// .dbNum(Long.valueOf(currentDbNum))
// .cmd("SET".getBytes())
// .ms(Long.parseLong(byte3))
// .build());
addCommandNum();
} else {
if (args == null || args.length <= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,27 @@ public void run(KeyValueEventEntity keyValueEventEntity){
SingleTaskDataManagerUtils.brokenStatusAndLog("被抛弃key数量到达阈值[" + errorCount + "],exception reason["+e.getMessage()+"]", this.getClass(), taskId);
}
}
log.error("[{}]抛弃key:{} ,class:[{}]:原因[{}]",taskId, keyName,event.getClass().toString(),e.getMessage());
String stringCommand=command;
if(event instanceof DefaultCommand){
try {
DefaultCommand defaultCommand= (DefaultCommand) event;
command= Strings.byteToString(defaultCommand.getCommand());
String [] args=Strings.byteToString(defaultCommand.getArgs());
StringBuilder commands=new StringBuilder();
commands.append(" ").append(command);
for (int i=0;i<args.length;i++){
String key=args[i];
commands.append(" ").append(key);
}
stringCommand=commands.toString();
}catch (Exception exq){
log.error("error command log error");
}

}
log.error("[{}]抛弃 command:[{}] key:{} ,class:[{}]:原因[{}] ",taskId,stringCommand, keyName,event.getClass().toString(),e.getMessage());

// log.error("[{}]抛弃key:{} ,class:[{}]:原因[{}]",taskId, keyName,event.getClass().toString(),e.getMessage());
DataCleanUtils.cleanData(keyValueEventEntity,event);
e.printStackTrace();
}finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public void run(Replication replication, KeyValueEventEntity eventEntity, TaskMo
if(eventEntity.getEvent() instanceof DefaultCommand){
DefaultCommand dc = (DefaultCommand) eventEntity.getEvent();
}
log.error("AofCommandSendStrategy error {} {}",e.getMessage(),e.getStackTrace());
throw new StartegyNodeException(e.getMessage()+"->AofCommandSendStrategy",e.getCause());
}
}
Expand Down

0 comments on commit 24bbb7b

Please sign in to comment.