refactoring

2.x.x
Nikita Koksharov
parent f82246c345
commit 5e56c4f977

@ -272,52 +272,43 @@ public class CommandDecoder extends ReplayingDecoder<State> {
int code = in.readByte(); int code = in.readByte();
Channel channel = ctx.channel(); Channel channel = ctx.channel();
if (code == '+') { if (code == '+') {
ByteBuf rb = in.readBytes(in.bytesBefore((byte) '\r')); int len = in.bytesBefore((byte) '\r');
try { String result = in.toString(in.readerIndex(), len, CharsetUtil.UTF_8);
String result = rb.toString(CharsetUtil.UTF_8); in.skipBytes(len + 2);
in.skipBytes(2);
handleResult(data, parts, result, skipConvertor, channel); handleResult(data, parts, result, skipConvertor, channel);
} finally {
rb.release();
}
} else if (code == '-') { } else if (code == '-') {
ByteBuf rb = in.readBytes(in.bytesBefore((byte) '\r')); int len = in.bytesBefore((byte) '\r');
try { String error = in.toString(in.readerIndex(), len, CharsetUtil.UTF_8);
String error = rb.toString(CharsetUtil.UTF_8); in.skipBytes(len + 2);
in.skipBytes(2); if (error.startsWith("MOVED")) {
String[] errorParts = error.split(" ");
if (error.startsWith("MOVED")) { int slot = Integer.valueOf(errorParts[1]);
String[] errorParts = error.split(" "); String addr = errorParts[2];
int slot = Integer.valueOf(errorParts[1]); data.tryFailure(new RedisMovedException(slot, addr));
String addr = errorParts[2]; } else if (error.startsWith("ASK")) {
data.tryFailure(new RedisMovedException(slot, addr)); String[] errorParts = error.split(" ");
} else if (error.startsWith("ASK")) { int slot = Integer.valueOf(errorParts[1]);
String[] errorParts = error.split(" "); String addr = errorParts[2];
int slot = Integer.valueOf(errorParts[1]); data.tryFailure(new RedisAskException(slot, addr));
String addr = errorParts[2]; } else if (error.startsWith("TRYAGAIN")) {
data.tryFailure(new RedisAskException(slot, addr)); data.tryFailure(new RedisTryAgainException(error
} else if (error.startsWith("TRYAGAIN")) { + ". channel: " + channel + " data: " + data));
data.tryFailure(new RedisTryAgainException(error } else if (error.startsWith("LOADING")) {
+ ". channel: " + channel + " data: " + data)); data.tryFailure(new RedisLoadingException(error
} else if (error.startsWith("LOADING")) { + ". channel: " + channel + " data: " + data));
data.tryFailure(new RedisLoadingException(error } else if (error.startsWith("OOM")) {
+ ". channel: " + channel + " data: " + data)); data.tryFailure(new RedisOutOfMemoryException(error.split("OOM ")[1]
} else if (error.startsWith("OOM")) { + ". channel: " + channel + " data: " + data));
data.tryFailure(new RedisOutOfMemoryException(error.split("OOM ")[1] } else if (error.contains("-OOM ")) {
+ ". channel: " + channel + " data: " + data)); data.tryFailure(new RedisOutOfMemoryException(error.split("-OOM ")[1]
} else if (error.contains("-OOM ")) { + ". channel: " + channel + " data: " + data));
data.tryFailure(new RedisOutOfMemoryException(error.split("-OOM ")[1] } else {
+ ". channel: " + channel + " data: " + data)); if (data != null) {
data.tryFailure(new RedisException(error + ". channel: " + channel + " command: " + LogHelper.toString(data)));
} else { } else {
if (data != null) { log.error("Error message from Redis: {} channel: {}", error, channel);
data.tryFailure(new RedisException(error + ". channel: " + channel + " command: " + LogHelper.toString(data)));
} else {
log.error("Error message from Redis: {} channel: {}", error, channel);
}
} }
} finally {
rb.release();
} }
} else if (code == ':') { } else if (code == ':') {
Long result = readLong(in); Long result = readLong(in);

Loading…
Cancel
Save