Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #11449] Support RESP3 for codec-redis #11448

Open
wants to merge 12 commits into
base: 4.1
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2021 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:
*
* https://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.StringUtil;
import io.netty.util.internal.UnstableApi;

import java.math.BigInteger;

/**
* Abstract class for Number type message.
*/
@UnstableApi
public abstract class AbstractNumberRedisMessage implements RedisMessage {

protected final Number value;

/**
* For create a {@link IntegerRedisMessage} the given int {@code value}.
*
* @param value the message content.
*/
AbstractNumberRedisMessage(long value) {
jjz921024 marked this conversation as resolved.
Show resolved Hide resolved
this.value = value;
}

/**
* For create a {@link DoubleRedisMessage} the given double {@code value}.
*
* @param value the message content.
*/
AbstractNumberRedisMessage(double value) {
this.value = value;
}

/**
* For create a {@link BigNumberRedisMessage} the given BigInteger {@code value}.
*
* @param value the message content.
*/
AbstractNumberRedisMessage(BigInteger value) {
this.value = value;
}

@Override
public String toString() {
return new StringBuilder(StringUtil.simpleClassName(this))
.append('[')
.append("value=")
.append(value)
.append(']').toString();
}

jjz921024 marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright 2021 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:
*
* https://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;

import java.math.BigInteger;

/**
* Big number of <a href="https://github.com/antirez/RESP3/blob/master/spec.md">RESP3</a>.
*/
@UnstableApi
public class BigNumberRedisMessage extends AbstractNumberRedisMessage {
jjz921024 marked this conversation as resolved.
Show resolved Hide resolved

/**
* Creates a {@link BigNumberRedisMessage} for the given byte {@code content}.
*
* @param value the message content.
*/
public BigNumberRedisMessage(byte[] value) {
this(new String(value));
}

/**
* Creates a {@link BigNumberRedisMessage} for the given string {@code content}.
*
* @param value the message content.
*/
public BigNumberRedisMessage(String value) {
this(new BigInteger(value));
}

/**
* Creates a {@link BigNumberRedisMessage} for the given BigInteger {@code content}.
*
* @param value the message content.
*/
public BigNumberRedisMessage(BigInteger value) {
super(value);
}

/**
* Get string represent the value of this {@link DoubleRedisMessage}.
*
* @return string value
*/
public String value() {
return value.toString();
}

jjz921024 marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2021 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:
*
* https://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.StringUtil;
import io.netty.util.internal.UnstableApi;

/**
* Boolean of <a href="https://github.com/antirez/RESP3/blob/master/spec.md">RESP3</a>.
*/
@UnstableApi
public class BooleanRedisMessage implements RedisMessage {

private boolean value;

public static final BooleanRedisMessage TRUE_BOOLEAN_INSTANCE = new BooleanRedisMessage(true);

public static final BooleanRedisMessage FALSE_BOOLEAN_INSTANCE = new BooleanRedisMessage(false);
jjz921024 marked this conversation as resolved.
Show resolved Hide resolved

/**
* Creates a {@link BooleanRedisMessage} for the given {@code value}.
*
* @param value true or false.
*/
private BooleanRedisMessage(boolean value) {
this.value = value;
}

/**
* Get boolean value of this {@link BooleanRedisMessage}.
*
* @return boolean value
*/
public boolean value() {
return value;
}

@Override
public String toString() {
return new StringBuilder(StringUtil.simpleClassName(this))
.append('[')
.append("value=")
.append(value)
.append(']').toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2021 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:
*
* https://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;

public class BulkErrorStringHeaderRedisMessage extends BulkStringHeaderRedisMessage {
jjz921024 marked this conversation as resolved.
Show resolved Hide resolved

/**
* Creates a {@link BulkErrorStringHeaderRedisMessage}.
*
* @param bulkStringLength follow content length.
*/
public BulkErrorStringHeaderRedisMessage(int bulkStringLength) {
super(bulkStringLength);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2021 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:
*
* https://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;

/**
* Double of <a href="https://github.com/antirez/RESP3/blob/master/spec.md">RESP3</a>.
*/
@UnstableApi
public class DoubleRedisMessage extends AbstractNumberRedisMessage {
jjz921024 marked this conversation as resolved.
Show resolved Hide resolved

public static final DoubleRedisMessage POSITIVE_INFINITY_DOUBLE_INSTANCE = new DoubleRedisMessage(Double.MAX_VALUE);

public static final DoubleRedisMessage NEGATIVE_INFINITY_DOUBLE_INSTANCE = new DoubleRedisMessage(Double.MIN_VALUE);
jjz921024 marked this conversation as resolved.
Show resolved Hide resolved

/**
* Creates a {@link DoubleRedisMessage} for the given {@code content}.
*
* @param value the message content.
*/
public DoubleRedisMessage(double value) {
super(value);
}

/**
* Get long value of this {@link DoubleRedisMessage}.
*
* @return double value
*/
public double value() {
return value.doubleValue();
}

jjz921024 marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2021 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:
*
* https://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.buffer.ByteBuf;

public class FullBulkErrorStringRedisMessage extends FullBulkStringRedisMessage {
jjz921024 marked this conversation as resolved.
Show resolved Hide resolved

/**
* Creates a {@link FullBulkErrorStringRedisMessage} for the given {@code content}.
*
* @param content the content, must not be {@code null}. If content is null or empty,
* use {@link NullRedisMessage#INSTANCE instead of constructor.
*/
public FullBulkErrorStringRedisMessage(ByteBuf content) {
super(content);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,21 @@

package io.netty.handler.codec.redis;

import io.netty.util.internal.StringUtil;
import io.netty.util.internal.UnstableApi;

/**
* Integers of <a href="https://redis.io/topics/protocol">RESP</a>.
*/
@UnstableApi
public final class IntegerRedisMessage implements RedisMessage {

private final long value;
public final class IntegerRedisMessage extends AbstractNumberRedisMessage {

/**
* Creates a {@link IntegerRedisMessage} for the given {@code content}.
*
* @param value the message content.
*/
public IntegerRedisMessage(long value) {
this.value = value;
super(value);
}

/**
Expand All @@ -41,15 +38,7 @@ public IntegerRedisMessage(long value) {
* @return long value
*/
public long value() {
return value;
return value.intValue();
}

@Override
public String toString() {
return new StringBuilder(StringUtil.simpleClassName(this))
.append('[')
.append("value=")
.append(value)
.append(']').toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2021 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:
*
* https://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;

/**
* NULL of <a href="https://github.com/antirez/RESP3/blob/master/spec.md">RESP3</a>.
*/
@UnstableApi
public class NullRedisMessage implements RedisMessage {

public static final NullRedisMessage INSTANCE = new NullRedisMessage();

private NullRedisMessage() {
}

jjz921024 marked this conversation as resolved.
Show resolved Hide resolved
}