diff --git a/codec-redis/src/main/java/io/netty/handler/codec/redis/AbstractStringRedisMessage.java b/codec-redis/src/main/java/io/netty/handler/codec/redis/AbstractStringRedisMessage.java
index 880c4f325f..19be6c126b 100644
--- a/codec-redis/src/main/java/io/netty/handler/codec/redis/AbstractStringRedisMessage.java
+++ b/codec-redis/src/main/java/io/netty/handler/codec/redis/AbstractStringRedisMessage.java
@@ -16,6 +16,7 @@
package io.netty.handler.codec.redis;
import io.netty.util.internal.ObjectUtil;
+import io.netty.util.internal.StringUtil;
import io.netty.util.internal.UnstableApi;
/**
@@ -38,4 +39,14 @@ public abstract class AbstractStringRedisMessage implements RedisMessage {
public final String content() {
return content;
}
+
+ @Override
+ public String toString() {
+ return new StringBuilder(StringUtil.simpleClassName(this))
+ .append('[')
+ .append("content=")
+ .append(content)
+ .append(']').toString();
+ }
+
}
diff --git a/codec-redis/src/main/java/io/netty/handler/codec/redis/ArrayRedisMessage.java b/codec-redis/src/main/java/io/netty/handler/codec/redis/ArrayRedisMessage.java
index 484871de8f..3421d328be 100644
--- a/codec-redis/src/main/java/io/netty/handler/codec/redis/ArrayRedisMessage.java
+++ b/codec-redis/src/main/java/io/netty/handler/codec/redis/ArrayRedisMessage.java
@@ -137,10 +137,6 @@ public class ArrayRedisMessage extends AbstractReferenceCounted implements Redis
* A predefined empty array instance for {@link ArrayRedisMessage}.
*/
public static final ArrayRedisMessage EMPTY_INSTANCE = new ArrayRedisMessage() {
- @Override
- public boolean isNull() {
- return false;
- }
@Override
public ArrayRedisMessage retain() {
diff --git a/codec-redis/src/main/java/io/netty/handler/codec/redis/ErrorRedisMessage.java b/codec-redis/src/main/java/io/netty/handler/codec/redis/ErrorRedisMessage.java
index 5546fc68ea..33a787e0ff 100644
--- a/codec-redis/src/main/java/io/netty/handler/codec/redis/ErrorRedisMessage.java
+++ b/codec-redis/src/main/java/io/netty/handler/codec/redis/ErrorRedisMessage.java
@@ -15,7 +15,6 @@
package io.netty.handler.codec.redis;
-import io.netty.util.internal.StringUtil;
import io.netty.util.internal.UnstableApi;
/**
@@ -33,12 +32,4 @@ public final class ErrorRedisMessage extends AbstractStringRedisMessage {
super(content);
}
- @Override
- public String toString() {
- return new StringBuilder(StringUtil.simpleClassName(this))
- .append('[')
- .append("content=")
- .append(content())
- .append(']').toString();
- }
}
diff --git a/codec-redis/src/main/java/io/netty/handler/codec/redis/InlineCommandRedisMessage.java b/codec-redis/src/main/java/io/netty/handler/codec/redis/InlineCommandRedisMessage.java
new file mode 100644
index 0000000000..b648973ba2
--- /dev/null
+++ b/codec-redis/src/main/java/io/netty/handler/codec/redis/InlineCommandRedisMessage.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2018 The Netty Project
+ *
+ * The Netty Project licenses this file to you under the Apache License, version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package io.netty.handler.codec.redis;
+
+import io.netty.util.internal.UnstableApi;
+
+/**
+ * Inline commands of RESP.
+ */
+@UnstableApi
+public final class InlineCommandRedisMessage extends AbstractStringRedisMessage {
+
+ /**
+ * Creates a {@link InlineCommandRedisMessage} for the given {@code content}.
+ *
+ * @param content the message content, must not be {@code null}.
+ */
+ public InlineCommandRedisMessage(String content) {
+ super(content);
+ }
+
+}
diff --git a/codec-redis/src/main/java/io/netty/handler/codec/redis/RedisConstants.java b/codec-redis/src/main/java/io/netty/handler/codec/redis/RedisConstants.java
index 9fae6f1232..ca68840ac1 100644
--- a/codec-redis/src/main/java/io/netty/handler/codec/redis/RedisConstants.java
+++ b/codec-redis/src/main/java/io/netty/handler/codec/redis/RedisConstants.java
@@ -33,6 +33,9 @@ final class RedisConstants {
static final int REDIS_MESSAGE_MAX_LENGTH = 512 * 1024 * 1024; // 512MB
+ // 64KB is max inline length of current Redis server implementation.
+ static final int REDIS_INLINE_MESSAGE_MAX_LENGTH = 64 * 1024;
+
static final int POSITIVE_LONG_MAX_LENGTH = 19; // length of Long.MAX_VALUE
static final int LONG_MAX_LENGTH = POSITIVE_LONG_MAX_LENGTH + 1; // +1 is sign
diff --git a/codec-redis/src/main/java/io/netty/handler/codec/redis/RedisDecoder.java b/codec-redis/src/main/java/io/netty/handler/codec/redis/RedisDecoder.java
index 4c70444efa..ad5e68d29e 100644
--- a/codec-redis/src/main/java/io/netty/handler/codec/redis/RedisDecoder.java
+++ b/codec-redis/src/main/java/io/netty/handler/codec/redis/RedisDecoder.java
@@ -36,6 +36,7 @@ public final class RedisDecoder extends ByteToMessageDecoder {
private final ToPositiveLongProcessor toPositiveLongProcessor = new ToPositiveLongProcessor();
+ private final boolean decodeInlineCommands;
private final int maxInlineMessageLength;
private final RedisMessagePool messagePool;
@@ -53,25 +54,44 @@ public final class RedisDecoder extends ByteToMessageDecoder {
}
/**
- * Creates a new instance with default {@code maxInlineMessageLength} and {@code messagePool}.
+ * Creates a new instance with default {@code maxInlineMessageLength} and {@code messagePool}
+ * and inline command decoding disabled.
*/
public RedisDecoder() {
- // 1024 * 64 is max inline length of current Redis server implementation.
- this(1024 * 64, FixedRedisMessagePool.INSTANCE);
+ this(false);
+ }
+
+ /**
+ * Creates a new instance with default {@code maxInlineMessageLength} and {@code messagePool}.
+ * @param decodeInlineCommands if {@code true}, inline commands will be decoded.
+ */
+ public RedisDecoder(boolean decodeInlineCommands) {
+ this(RedisConstants.REDIS_INLINE_MESSAGE_MAX_LENGTH, FixedRedisMessagePool.INSTANCE, decodeInlineCommands);
+ }
+
+ /**
+ * Creates a new instance with inline command decoding disabled.
+ * @param maxInlineMessageLength the maximum length of inline message.
+ * @param messagePool the predefined message pool.
+ */
+ public RedisDecoder(int maxInlineMessageLength, RedisMessagePool messagePool) {
+ this(maxInlineMessageLength, messagePool, false);
}
/**
* Creates a new instance.
* @param maxInlineMessageLength the maximum length of inline message.
* @param messagePool the predefined message pool.
+ * @param decodeInlineCommands if {@code true}, inline commands will be decoded.
*/
- public RedisDecoder(int maxInlineMessageLength, RedisMessagePool messagePool) {
+ public RedisDecoder(int maxInlineMessageLength, RedisMessagePool messagePool, boolean decodeInlineCommands) {
if (maxInlineMessageLength <= 0 || maxInlineMessageLength > RedisConstants.REDIS_MESSAGE_MAX_LENGTH) {
throw new RedisCodecException("maxInlineMessageLength: " + maxInlineMessageLength +
" (expected: <= " + RedisConstants.REDIS_MESSAGE_MAX_LENGTH + ")");
}
this.maxInlineMessageLength = maxInlineMessageLength;
this.messagePool = messagePool;
+ this.decodeInlineCommands = decodeInlineCommands;
}
@Override
@@ -126,7 +146,8 @@ public final class RedisDecoder extends ByteToMessageDecoder {
if (!in.isReadable()) {
return false;
}
- type = RedisMessageType.valueOf(in.readByte());
+
+ type = RedisMessageType.readFrom(in, decodeInlineCommands);
state = type.isInline() ? State.DECODE_INLINE : State.DECODE_LENGTH;
return true;
}
@@ -233,6 +254,8 @@ public final class RedisDecoder extends ByteToMessageDecoder {
private RedisMessage newInlineRedisMessage(RedisMessageType messageType, ByteBuf content) {
switch (messageType) {
+ case INLINE_COMMAND:
+ return new InlineCommandRedisMessage(content.toString(CharsetUtil.UTF_8));
case SIMPLE_STRING: {
SimpleStringRedisMessage cached = messagePool.getSimpleString(content);
return cached != null ? cached : new SimpleStringRedisMessage(content.toString(CharsetUtil.UTF_8));
diff --git a/codec-redis/src/main/java/io/netty/handler/codec/redis/RedisEncoder.java b/codec-redis/src/main/java/io/netty/handler/codec/redis/RedisEncoder.java
index 45fad5e511..9a72f451c9 100644
--- a/codec-redis/src/main/java/io/netty/handler/codec/redis/RedisEncoder.java
+++ b/codec-redis/src/main/java/io/netty/handler/codec/redis/RedisEncoder.java
@@ -62,7 +62,9 @@ public class RedisEncoder extends MessageToMessageEncoder {
}
private void writeRedisMessage(ByteBufAllocator allocator, RedisMessage msg, List