Fixed - Wrong parsing of RScript.ReturnType.MULTI result. #1251

pull/1263/head
Nikita 7 years ago
parent e37729deee
commit 1c4df64185

@ -137,12 +137,11 @@ public class CommandDecoder extends ReplayingDecoder<State> {
decodeList(in, cmd, firstLevel.getParts(), ctx.channel(), secondLevel.getSize(), secondLevel.getParts());
Channel channel = ctx.channel();
MultiDecoder<Object> decoder = messageDecoder(cmd, firstLevel.getParts());
if (decoder != null) {
Object result = decoder.decode(firstLevel.getParts(), state());
if (data != null) {
handleResult(cmd, null, result, true, channel);
handleResult(cmd, null, result, true, ctx.channel());
}
}
}
@ -151,11 +150,22 @@ public class CommandDecoder extends ReplayingDecoder<State> {
if (firstLevel.getParts().isEmpty()) {
state().resetLevel();
decode(in, cmd, null, ctx.channel());
} else {
if (firstLevel.getLastList() != null) {
decodeList(in, cmd, firstLevel.getParts(), ctx.channel(), firstLevel.getLastListSize(), firstLevel.getLastList());
firstLevel.setLastList(null);
firstLevel.setLastListSize(0);
if (in.isReadable()) {
decode(in, cmd, firstLevel.getParts(), ctx.channel());
}
decodeList(in, cmd, null, ctx.channel(), 0, firstLevel.getParts());
} else {
decodeList(in, cmd, null, ctx.channel(), firstLevel.getSize(), firstLevel.getParts());
}
}
}
}
private void decodeCommandBatch(ChannelHandlerContext ctx, ByteBuf in, QueueCommand data,
CommandsData commandBatch) {
@ -287,10 +297,16 @@ public class CommandDecoder extends ReplayingDecoder<State> {
}
handleResult(data, parts, result, false, channel);
} else if (code == '*') {
int level = state().incLevel();
long size = readLong(in);
List<Object> respParts;
StateLevel lastLevel = state().getLastLevel();
if (lastLevel != null && lastLevel.getSize() != lastLevel.getParts().size()) {
respParts = new ArrayList<Object>();
lastLevel.setLastListSize(size);
lastLevel.setLastList(respParts);
} else {
int level = state().incLevel();
if (state().getLevels().size()-1 >= level) {
StateLevel stateLevel = state().getLevels().get(level);
respParts = stateLevel.getParts();
@ -301,8 +317,14 @@ public class CommandDecoder extends ReplayingDecoder<State> {
state().addLevel(new StateLevel(size, respParts));
}
}
}
decodeList(in, data, parts, channel, size, respParts);
if (lastLevel != null && lastLevel.getLastList() != null) {
lastLevel.setLastList(null);
lastLevel.setLastListSize(0);
}
} else {
String dataStr = in.toString(0, in.writerIndex(), CharsetUtil.UTF_8);
throw new IllegalStateException("Can't decode replay: " + dataStr);

@ -28,7 +28,6 @@ public class State {
private int level = -1;
private List<StateLevel> levels;
private DecoderState decoderStateCopy;
private final boolean makeCheckpoint;
public State(boolean makeCheckpoint) {
@ -41,6 +40,7 @@ public class State {
public void resetLevel() {
level = -1;
levels.clear();
}
public int decLevel() {
return --level;
@ -49,6 +49,13 @@ public class State {
return ++level;
}
public StateLevel getLastLevel() {
if (levels == null || levels.isEmpty()) {
return null;
}
return levels.get(level);
}
public void addLevel(StateLevel stateLevel) {
if (levels == null) {
levels = new ArrayList<StateLevel>(2);
@ -76,17 +83,10 @@ public class State {
this.decoderState = decoderState;
}
public DecoderState getDecoderStateCopy() {
return decoderStateCopy;
}
public void setDecoderStateCopy(DecoderState decoderStateCopy) {
this.decoderStateCopy = decoderStateCopy;
}
@Override
public String toString() {
return "State [batchIndex=" + batchIndex + ", decoderState=" + decoderState + ", level=" + level + ", levels="
+ levels + ", decoderStateCopy=" + decoderStateCopy + "]";
+ levels + "]";
}

@ -21,6 +21,8 @@ public class StateLevel {
private long size;
private List<Object> parts;
private long lastListSize;
private List<Object> lastList;
public StateLevel(long size, List<Object> parts) {
super();
@ -28,6 +30,20 @@ public class StateLevel {
this.parts = parts;
}
public long getLastListSize() {
return lastListSize;
}
public void setLastListSize(long lastListSize) {
this.lastListSize = lastListSize;
}
public List<Object> getLastList() {
return lastList;
}
public void setLastList(List<Object> lastList) {
this.lastList = lastList;
}
public long getSize() {
return size;
}

@ -5,16 +5,51 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import org.junit.Assert;
import org.junit.Test;
import org.redisson.api.RFuture;
import org.redisson.api.RLexSortedSet;
import org.redisson.api.RScript;
import org.redisson.api.RScript.Mode;
import org.redisson.client.RedisException;
import org.redisson.client.codec.StringCodec;
public class RedissonScriptTest extends BaseTest {
@Test
public void testMulti() throws InterruptedException, ExecutionException {
RLexSortedSet idx2 = redisson.getLexSortedSet("ABCD17436");
Long l = new Long("1506524856000");
for (int i = 0; i < 100; i++) {
String s = "DENY" + "\t" + "TESTREDISSON" + "\t"
+ Long.valueOf(l) + "\t" + "helloworld_hongqin";
idx2.add(s);
l = l + 1;
}
StringCodec codec = new StringCodec();
String max = "'[DENY" + "\t" + "TESTREDISSON" + "\t" + "1506524856099'";
String min = "'[DENY" + "\t" + "TESTREDISSON" + "\t" + "1506524856000'";
String luaScript1= "local d = {}; d[1] = redis.call('zrevrangebylex','ABCD17436'," +max+","+min+",'LIMIT',0,5); ";
luaScript1= luaScript1 + " d[2] = redis.call('zrevrangebylex','ABCD17436'," +max+","+min+",'LIMIT',0,15); ";
luaScript1= luaScript1 + " d[3] = redis.call('zrevrangebylex','ABCD17436'," +max+","+min+",'LIMIT',0,25); ";
luaScript1 = luaScript1 + " return d;";
Future<Object> r1 = redisson.getScript().evalAsync(RScript.Mode.READ_ONLY, codec,
luaScript1,
RScript.ReturnType.MULTI, Collections.emptyList());
List<List<Object>> obj1 = (List<List<Object>>) r1.get();
assertThat(obj1).hasSize(3);
assertThat(obj1.get(0)).hasSize(5);
assertThat(obj1.get(1)).hasSize(15);
assertThat(obj1.get(2)).hasSize(25);
}
@Test
public void testEval() {
RScript script = redisson.getScript();

Loading…
Cancel
Save