Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
StreamEntry support Binary instead of String
Browse files Browse the repository at this point in the history
Revert

Add StreamEntryBinary
thachlp committed Apr 19, 2024

Verified

This commit was signed with the committer’s verified signature.
thachlp Thach Le
1 parent 2d42338 commit 431f721
Showing 2 changed files with 51 additions and 8 deletions.
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
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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);

0 comments on commit 431f721

Please sign in to comment.