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

StreamEntry support Binary #3803

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 43 additions & 0 deletions src/main/java/redis/clients/jedis/resps/StreamEntryBinary.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package redis.clients.jedis.resps;

import redis.clients.jedis.StreamEntryID;

import java.io.IOException;
import java.io.Serializable;
import java.util.Map;

public class StreamEntryBinary implements Serializable {

private static final long serialVersionUID = 1L;

private StreamEntryID id;
private Map<byte[], byte[]> fields;

public StreamEntryBinary(StreamEntryID id, Map<byte[], byte[]> fields) {
this.id = id;
this.fields = fields;
}

public StreamEntryID getID() {
return id;
}

public Map<byte[], byte[]> getFields() {
return fields;
}

@Override
public String toString() {
return id + " " + fields;
}

private void writeObject(java.io.ObjectOutputStream out) throws IOException {
out.writeUnshared(this.id);
out.writeUnshared(this.fields);
}

private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
this.id = (StreamEntryID) in.readUnshared();
this.fields = (Map<byte[], byte[]>) in.readUnshared();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ public void testXpending() {
String key = "mystream";
String groupName = "mygroup";
StreamPendingSummary expectedSummary = new StreamPendingSummary(10L,
new StreamEntryID("0-0"), new StreamEntryID("0-1"), Collections.emptyMap());
new StreamEntryID("0-0"), new StreamEntryID("0-1"), Collections.emptyMap());

when(commandObjects.xpending(key, groupName)).thenReturn(streamPendingSummaryCommandObject);
when(commandExecutor.executeCommand(streamPendingSummaryCommandObject)).thenReturn(expectedSummary);
Expand Down Expand Up @@ -827,8 +827,8 @@ public void testXrangeBinary() {
byte[] start = "0-0".getBytes();
byte[] end = "+".getBytes();
List<Object> expectedRange = Arrays.asList(
new StreamEntry(new StreamEntryID("0-0"), Collections.singletonMap("field1", "value1")),
new StreamEntry(new StreamEntryID("0-1"), Collections.singletonMap("field2", "value2")));
new StreamEntry(new StreamEntryID("0-0"), Collections.singletonMap("field1", "value1")),
new StreamEntry(new StreamEntryID("0-1"), Collections.singletonMap("field2", "value2")));

when(commandObjects.xrange(key, start, end)).thenReturn(listObjectCommandObject);
when(commandExecutor.executeCommand(listObjectCommandObject)).thenReturn(expectedRange);
Expand Down Expand Up @@ -870,8 +870,8 @@ public void testXrangeWithCountBinary() {
byte[] end = "+".getBytes();
int count = 2;
List<Object> expectedRange = Arrays.asList(
new StreamEntry(new StreamEntryID("0-0"), Collections.singletonMap("field1", "value1")),
new StreamEntry(new StreamEntryID("0-1"), Collections.singletonMap("field2", "value2")));
new StreamEntry(new StreamEntryID("0-0"), Collections.singletonMap("field1", "value1")),
new StreamEntry(new StreamEntryID("0-1"), Collections.singletonMap("field2", "value2")));

when(commandObjects.xrange(key, start, end, count)).thenReturn(listObjectCommandObject);
when(commandExecutor.executeCommand(listObjectCommandObject)).thenReturn(expectedRange);
Expand Down Expand Up @@ -1061,8 +1061,8 @@ public void testXrevrangeBinary() {
byte[] end = "+".getBytes();
byte[] start = "0-0".getBytes();
List<Object> expectedReverseRange = Arrays.asList(
new StreamEntry(new StreamEntryID("0-1"), Collections.singletonMap("field2", "value2")),
new StreamEntry(new StreamEntryID("0-0"), Collections.singletonMap("field1", "value1")));
new StreamEntry(new StreamEntryID("0-1"), Collections.singletonMap("field2", "value2")),
new StreamEntry(new StreamEntryID("0-0"), Collections.singletonMap("field1", "value1")));

when(commandObjects.xrevrange(key, end, start)).thenReturn(listObjectCommandObject);
when(commandExecutor.executeCommand(listObjectCommandObject)).thenReturn(expectedReverseRange);
Expand Down Expand Up @@ -1104,7 +1104,7 @@ public void testXrevrangeWithCountBinary() {
byte[] start = "0-0".getBytes();
int count = 1;
List<Object> expectedReverseRange = Collections.singletonList(
new StreamEntry(new StreamEntryID("0-1"), Collections.singletonMap("field2", "value2")));
new StreamEntry(new StreamEntryID("0-1"), Collections.singletonMap("field2", "value2")));

when(commandObjects.xrevrange(key, end, start, count)).thenReturn(listObjectCommandObject);
when(commandExecutor.executeCommand(listObjectCommandObject)).thenReturn(expectedReverseRange);
Expand Down