-
-
Notifications
You must be signed in to change notification settings - Fork 15.8k
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
jjz921024
wants to merge
12
commits into
netty:4.1
Choose a base branch
from
jjz921024:resp3
base: 4.1
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7d37daa
Support encode/decode Null,Boolean,Double,BigNumber types message
jjz921024 76567ce
Fix bug about create BigNumberRedisMessage using different constructor
jjz921024 31ef104
Support blob error message
jjz921024 5a8c417
Support encode/decode SetRedisMessage & extract common Aggregated Typ…
jjz921024 62be5ac
fix check style
jjz921024 12a636f
fix code for review
jjz921024 1c97186
Support encode/decode Map types message
jjz921024 468b130
fix a bug about Map header length
jjz921024 3d41506
support encode/decode Verbatim string
jjz921024 0a0224f
support encode/decode Push types message
jjz921024 103d6c4
for review
jjz921024 09f9cdb
for compatibility
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
codec-redis/src/main/java/io/netty/handler/codec/redis/AbstractCollectionRedisMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* 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.AbstractReferenceCounted; | ||
import io.netty.util.ReferenceCountUtil; | ||
import io.netty.util.internal.ObjectUtil; | ||
import io.netty.util.internal.StringUtil; | ||
import io.netty.util.internal.UnstableApi; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* Abstract class for Aggregate data types message. | ||
*/ | ||
@UnstableApi | ||
public abstract class AbstractCollectionRedisMessage extends AbstractReferenceCounted | ||
implements RedisMessage, AggregatedRedisMessage { | ||
|
||
protected Collection<RedisMessage> children; | ||
|
||
public AbstractCollectionRedisMessage() { | ||
jjz921024 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
public AbstractCollectionRedisMessage(Collection<RedisMessage> children) { | ||
jjz921024 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.children = ObjectUtil.checkNotNull(children, "children"); | ||
} | ||
|
||
/** | ||
* | ||
* @return | ||
*/ | ||
public abstract Collection<RedisMessage> children(); | ||
jjz921024 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@Override | ||
protected void deallocate() { | ||
for (RedisMessage msg : children) { | ||
jjz921024 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ReferenceCountUtil.release(msg); | ||
} | ||
} | ||
|
||
@Override | ||
public AbstractCollectionRedisMessage touch(Object hint) { | ||
for (RedisMessage msg : children) { | ||
jjz921024 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ReferenceCountUtil.touch(msg); | ||
} | ||
return this; | ||
} | ||
|
||
/** | ||
* Returns whether the content of this message is {@code null}. | ||
* | ||
* @return indicates whether the content of this message is {@code null}. | ||
*/ | ||
public boolean isNull() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new StringBuilder(StringUtil.simpleClassName(this)) | ||
.append('[') | ||
.append("children=") | ||
.append(children.size()) | ||
.append(']').toString(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
codec-redis/src/main/java/io/netty/handler/codec/redis/AbstractMapRedisMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* 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.ObjectUtil; | ||
import io.netty.util.internal.UnstableApi; | ||
|
||
import java.util.Map; | ||
|
||
@UnstableApi | ||
public abstract class AbstractMapRedisMessage implements AggregatedRedisMessage { | ||
|
||
public Map<RedisMessage, RedisMessage> children; | ||
jjz921024 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public AbstractMapRedisMessage(Map<RedisMessage, RedisMessage> children) { | ||
jjz921024 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.children = ObjectUtil.checkNotNull(children, "children"); | ||
} | ||
|
||
/** | ||
* Get children of this Map. It can be null or empty. | ||
* | ||
* @return Map of {@link RedisMessage}s. | ||
*/ | ||
public Map<RedisMessage, RedisMessage> children() { | ||
return children; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
codec-redis/src/main/java/io/netty/handler/codec/redis/AbstractNumberRedisMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 types 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
|
||
} |
64 changes: 64 additions & 0 deletions
64
codec-redis/src/main/java/io/netty/handler/codec/redis/AggregatedHeaderRedisMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.StringUtil; | ||
import io.netty.util.internal.UnstableApi; | ||
|
||
/** | ||
* Header of Redis Aggregated types Message. | ||
*/ | ||
@UnstableApi | ||
public abstract class AggregatedHeaderRedisMessage implements RedisMessage { | ||
|
||
private final long length; | ||
|
||
/** | ||
* Creates a {@link AggregatedHeaderRedisMessage} for the given {@code length}. | ||
*/ | ||
public AggregatedHeaderRedisMessage(long length) { | ||
jjz921024 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (length < RedisConstants.NULL_VALUE) { | ||
throw new RedisCodecException("length: " + length + " (expected: >= " + RedisConstants.NULL_VALUE + ")"); | ||
} | ||
this.length = length; | ||
} | ||
|
||
/** | ||
* Get length of this array object. | ||
*/ | ||
public final long length() { | ||
return length; | ||
} | ||
|
||
/** | ||
* Returns whether the content of this message is {@code null}. | ||
* | ||
* @return indicates whether the content of this message is {@code null}. | ||
*/ | ||
public boolean isNull() { | ||
return length == RedisConstants.NULL_VALUE; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new StringBuilder(StringUtil.simpleClassName(this)) | ||
.append('[') | ||
.append("length=") | ||
.append(length) | ||
.append(']').toString(); | ||
} | ||
|
||
jjz921024 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
7 changes: 7 additions & 0 deletions
7
codec-redis/src/main/java/io/netty/handler/codec/redis/AggregatedRedisMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.netty.handler.codec.redis; | ||
jjz921024 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* Just a marker interface for Aggregated data types | ||
*/ | ||
public interface AggregatedRedisMessage { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private final ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sub class
ArrayRedisMessage
andSetRedisMessage
need access thischildren
field on the abstract methodchildren()
for cast toList<Message>
orSet<Message>
, so it can't be private? but I had made itfinal