Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 5 additions & 5 deletions src/main/java/io/lettuce/core/output/ObjectOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ public ObjectOutput(RedisCodec<K, V> codec) {

@Override
public void set(long integer) {

if (!initialized) {
output = new ArrayList<>();
}

setValue(integer);
}

Expand Down Expand Up @@ -78,6 +73,11 @@ public void setSingle(ByteBuffer bytes) {
@SuppressWarnings("unchecked")
private void setValue(Object value) {

if (!initialized) {
output = new ArrayList<>();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we assign the actual value here ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Updated accordingly.

Top-level RESP3 scalar values are now assigned directly to output instead of being wrapped in a List.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If value is non-collection type, could we not initialize output as a List? Instead, just assign value to ouput?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion!

Updated the implementation to assign top-level non-collection RESP3 values directly to output.

Nested collection responses are unchanged because multi() / multiMap() still initialize the collection container before nested values are accumulated.

I also added regression tests covering top-level bulk string, boolean, double, and integer responses.

initialized = true;
}

if (output != null) {

if (output instanceof Collection) {
Expand Down
42 changes: 42 additions & 0 deletions src/test/java/io/lettuce/core/output/ObjectOutputUnitTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static io.lettuce.TestTags.UNIT_TEST;
import static org.assertj.core.api.Assertions.*;

import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;

Expand All @@ -22,6 +23,47 @@
@Tag(UNIT_TEST)
class ObjectOutputUnitTests {

@Test
void shouldParseTopLevelBulkString() {

String in = "$4\r\ntrue\r\n";
RedisStateMachine rsm = new RedisStateMachine(ByteBufAllocator.DEFAULT);
ObjectOutput<String, String> output = new ObjectOutput<>(StringCodec.UTF8);
rsm.decode(Unpooled.wrappedBuffer(in.getBytes(StandardCharsets.UTF_8)), output, exception -> {
throw (RuntimeException) exception;
});
assertThat(output.get()).isInstanceOf(List.class);
assertThat((List) output.get()).containsExactly("true");
}

@Test
void shouldParseTopLevelBoolean() {

RedisStateMachine rsm = new RedisStateMachine(ByteBufAllocator.DEFAULT);
ObjectOutput<String, String> output = new ObjectOutput<>(StringCodec.UTF8);
rsm.decode(Unpooled.wrappedBuffer("#t\r\n".getBytes(StandardCharsets.UTF_8)), output, exception -> {
throw (RuntimeException) exception;
});
rsm.decode(Unpooled.wrappedBuffer("#f\r\n".getBytes(StandardCharsets.UTF_8)), output, exception -> {
throw (RuntimeException) exception;
});
assertThat(output.get()).isInstanceOf(List.class);
assertThat((List) output.get()).containsExactly(true, false);
}

@Test
void shouldParseTopLevelDouble() {

String in = ",1.5\r\n";
RedisStateMachine rsm = new RedisStateMachine(ByteBufAllocator.DEFAULT);
ObjectOutput<String, String> output = new ObjectOutput<>(StringCodec.UTF8);
rsm.decode(Unpooled.wrappedBuffer(in.getBytes(StandardCharsets.UTF_8)), output, exception -> {
throw (RuntimeException) exception;
});
assertThat(output.get()).isInstanceOf(List.class);
assertThat((List) output.get()).containsExactly(1.5d);
}

@Test
void shouldParseHelloWithModules() {

Expand Down