Skip to content

Support RESP3 #1

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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.contrib.handler.codec.redis;

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

import java.util.Collection;

import static java.util.Objects.requireNonNull;

/**
* Abstract class for Aggregate data types message.
*/
@UnstableApi
public abstract class AbstractCollectionRedisMessage extends AbstractReferenceCounted
implements AggregatedRedisMessage {

protected final Collection<RedisMessage> children;

protected AbstractCollectionRedisMessage(Collection<RedisMessage> children) {
this.children = requireNonNull(children, "children");
}

protected abstract Collection<RedisMessage> children();

@Override
protected void deallocate() {
for (RedisMessage msg : children) {
ReferenceCountUtil.release(msg);
}
}

@Override
public AbstractCollectionRedisMessage touch(Object hint) {
for (RedisMessage msg : children) {
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();
}
}
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.contrib.handler.codec.redis;

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

import java.util.Collections;
import java.util.Map;

@UnstableApi
public abstract class AbstractMapRedisMessage extends AbstractReferenceCounted
implements AggregatedRedisMessage {

private final Map<RedisMessage, RedisMessage> children;

protected AbstractMapRedisMessage(Map<RedisMessage, RedisMessage> children) {
this.children = Collections.unmodifiableMap(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;
}

@Override
protected void deallocate() {
for (Map.Entry<RedisMessage, RedisMessage> messageEntry : children.entrySet()) {
ReferenceCountUtil.release(messageEntry.getKey());
ReferenceCountUtil.release(messageEntry.getValue());
}
}

@Override
public AbstractMapRedisMessage touch(Object hint) {
for (Map.Entry<RedisMessage, RedisMessage> messageEntry : children.entrySet()) {
ReferenceCountUtil.touch(messageEntry.getKey());
ReferenceCountUtil.touch(messageEntry.getValue());
}
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();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* 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.contrib.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.
*/
protected AbstractNumberRedisMessage(long value) {
this.value = value;
}

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

/**
* For create a {@link BigNumberRedisMessage} the given BigInteger {@code value}.
*
* @param value the message content.
*/
protected AbstractNumberRedisMessage(BigInteger value) {
this.value = 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
Expand Up @@ -27,7 +27,7 @@ public abstract class AbstractStringRedisMessage implements RedisMessage {

private final String content;

AbstractStringRedisMessage(String content) {
protected AbstractStringRedisMessage(String content) {
this.content = requireNonNull(content, "content");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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.contrib.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}.
*/
protected AggregatedHeaderRedisMessage(long length) {
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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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.contrib.handler.codec.redis;

/**
* Just a marker interface for Aggregated data types
*/
public interface AggregatedRedisMessage extends RedisMessage {
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,19 @@
*/
package io.netty.contrib.handler.codec.redis;

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

/**
* Header of Redis Array Message.
*/
@UnstableApi
public class ArrayHeaderRedisMessage implements RedisMessage {

private final long length;
public class ArrayHeaderRedisMessage extends AggregatedHeaderRedisMessage {

/**
* Creates a {@link ArrayHeaderRedisMessage} for the given {@code length}.
*/
public ArrayHeaderRedisMessage(long length) {
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;
super(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();
}
}
Loading