Skip to content

Commit

Permalink
fixed:fix bug caused when string is bigkey
Browse files Browse the repository at this point in the history
  • Loading branch information
pingxingshikong committed Aug 2, 2024
1 parent 7514348 commit f7e8fe1
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 21 deletions.
18 changes: 11 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
<scope>true</scope>
</dependency>

<!-- SQLite 驱动 -->
Expand Down Expand Up @@ -181,10 +181,18 @@
<version>4.13.1</version>
</dependency>

<!-- <dependency>-->
<!-- <groupId>org.projectlombok</groupId>-->
<!-- <artifactId>lombok</artifactId>-->
<!--&lt;!&ndash; <version>1.18.20.0</version>&ndash;&gt;-->
<!-- <optional>true</optional>-->
<!-- </dependency>-->

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
<version>1.18.20</version>
<scope>provided</scope>
</dependency>


Expand Down Expand Up @@ -226,11 +234,7 @@
<version>29.0-jre</version>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-bean-validators</artifactId>
<version>3.0.0</version>
</dependency>

<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class DefaultCommandNames {
public static final String INCR="INCR";
public static final String INCRBY="INCRBY";
public static final String INCRBYFLOAT="INCRBYFLOAT";

/**
* MSET key value [key value ...]
*Available since 1.0.1.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,45 @@ public void run(Replication replication, KeyValueEventEntity eventEntity, TaskMo

//String类型
if(typeEnum.equals(RedisCommandTypeEnum.STRING)){

BatchedKeyStringValueStringEvent valueString = (BatchedKeyStringValueStringEvent) event;
String stringKey=new String(valueString.getKey());
if (ms == null || ms <= 0L) {
Long res=client.append(duNum,valueString.getKey(), valueString.getValue());
iSyncerCompensator.append(duNum,valueString.getKey(), valueString.getValue(),res);
// Long res=client.append(duNum,valueString.getKey(), valueString.getValue());
// iSyncerCompensator.append(duNum,valueString.getKey(), valueString.getValue(),res);

if(valueString.getBatch()==0){
String res=client.set(duNum,valueString.getKey(), valueString.getValue());
iSyncerCompensator.set(duNum,valueString.getKey(), valueString.getValue(),res);
log.info("string set key 2 set key: {} ",stringKey);

}else {
Long res=client.append(duNum,valueString.getKey(), valueString.getValue());
iSyncerCompensator.append(duNum,valueString.getKey(), valueString.getValue(),res);
log.info("string append key 2 set key: {}",stringKey);
}


}else {
Long res=client.append(duNum,valueString.getKey(), valueString.getValue());
iSyncerCompensator.append(duNum,valueString.getKey(), valueString.getValue(),res);
// Long res=client.append(duNum,valueString.getKey(), valueString.getValue());
// iSyncerCompensator.append(duNum,valueString.getKey(), valueString.getValue(),res);

if(valueString.getBatch()==0){
String res=client.set(duNum,valueString.getKey(), valueString.getValue(),ms);
iSyncerCompensator.set(duNum,valueString.getKey(), valueString.getValue(),res);
log.info("string set key 2 set key: {} ms:{}",stringKey,ms);

}else {
Long res=client.append(duNum,valueString.getKey(), valueString.getValue());
iSyncerCompensator.append(duNum,valueString.getKey(), valueString.getValue(),res);
log.info("string append key 2 set key: {} ms:{}",stringKey,ms);
}

}





}else if(typeEnum.equals(RedisCommandTypeEnum.LIST)){
//list类型
BatchedKeyStringValueListEvent valueList = (BatchedKeyStringValueListEvent) event;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,38 @@ public void run(Replication replication, KeyValueEventEntity eventEntity, TaskMo
//String类型
if(typeEnum.equals(RedisCommandTypeEnum.STRING)){
BatchedKeyStringValueStringEvent valueString = (BatchedKeyStringValueStringEvent) event;
client.updateLastReplidAndOffset(replication.getConfig().getReplId(),replication.getConfig().getReplOffset());
String stringKey=new String(valueString.getKey());
if (ms == null || ms <= 0L) {
client.updateLastReplidAndOffset(replication.getConfig().getReplId(),replication.getConfig().getReplOffset());
Long res=client.append(duNum,valueString.getKey(), valueString.getValue());
iSyncerCompensator.append(duNum,valueString.getKey(), valueString.getValue(),res);
if(valueString.getBatch()==0){
String res=client.set(duNum,valueString.getKey(), valueString.getValue());
iSyncerCompensator.set(duNum,valueString.getKey(), valueString.getValue(),res);
log.info("string set key 2 set key:{}",stringKey);

}else {
Long res=client.append(duNum,valueString.getKey(), valueString.getValue());
iSyncerCompensator.append(duNum,valueString.getKey(), valueString.getValue(),res);
log.info("string append key 2 set key:{}",stringKey);
}
// Long res=client.append(duNum,valueString.getKey(), valueString.getValue());
// iSyncerCompensator.append(duNum,valueString.getKey(), valueString.getValue(),res);
// String res=client.set(duNum,valueString.getKey(), valueString.getValue());
// iSyncerCompensator.set(duNum,valueString.getKey(), valueString.getValue(),res);

}else {
Long res=client.append(duNum,valueString.getKey(), valueString.getValue());
iSyncerCompensator.append(duNum,valueString.getKey(), valueString.getValue(),res);
if(valueString.getBatch()==0){
String res=client.set(duNum,valueString.getKey(), valueString.getValue(),ms);
iSyncerCompensator.set(duNum,valueString.getKey(), valueString.getValue(),res);
// log.info("string set key 2 set {} {}",valueString.getKey(),valueString.getValue());
log.info("string set key 2 set key: {} ms:{}",stringKey,ms);
}else {
Long res=client.append(duNum,valueString.getKey(), valueString.getValue());
iSyncerCompensator.append(duNum,valueString.getKey(), valueString.getValue(),res);
log.info("string append key 2 set ms key: {} ms:{}",stringKey,ms);
}

// Long res=client.append(duNum,valueString.getKey(), valueString.getValue());
// iSyncerCompensator.append(duNum,valueString.getKey(), valueString.getValue(),res);
}
}else if(typeEnum.equals(RedisCommandTypeEnum.LIST)){
client.updateLastReplidAndOffset(replication.getConfig().getReplId(),replication.getConfig().getReplOffset());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ void initSysCommand() {


comanndResponseTypeMap.put("DEL", ComanndResponseType.builder().type(2).command("DEL").commandResponse("LONG").build());
comanndResponseTypeMap.put("UNLINK", ComanndResponseType.builder().type(2).command("UNLINK").commandResponse("LONG").build());
comanndResponseTypeMap.put("EXPIRE", ComanndResponseType.builder().type(2).command("EXPIRE").commandResponse("LONG").build());
comanndResponseTypeMap.put("EXPIREAT", ComanndResponseType.builder().type(2).command("EXPIREAT").commandResponse("LONG").build());
comanndResponseTypeMap.put("MIGRATE", ComanndResponseType.builder().type(1).command("MIGRATE").commandResponse("OK").build());
Expand Down Expand Up @@ -253,8 +254,6 @@ public boolean isObjectSuccess(Object res, String cmd) {
} else if (responseType.getType() == 9) {
return true;
}


} else {
log.warn("[{}]command->type[{}]未被定义", stringCmd, cmd);
return true;
Expand Down
4 changes: 2 additions & 2 deletions syncer-webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</parent>
<groupId>syncer</groupId>
<artifactId>syncer-webapp</artifactId>
<version>3.3.3.3</version>
<version>3.3.3.7</version>
<name>redissyncer-server</name>
<description>Demo project for Spring Boot</description>

Expand Down Expand Up @@ -47,7 +47,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>true</scope>
<scope>runtime</scope>
</dependency>


Expand Down

0 comments on commit f7e8fe1

Please sign in to comment.