From dcebe094b4edadee16c7b1230b1b528512798760 Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Sun, 29 May 2022 11:47:08 +0600 Subject: [PATCH] Introduce factory MINIMUM_ID and MAXIMUM_ID for StreamEntryID (#3006) --- .../redis/clients/jedis/StreamEntryID.java | 127 +++++++++++------- .../commands/jedis/StreamsCommandsTest.java | 12 ++ 2 files changed, 89 insertions(+), 50 deletions(-) diff --git a/src/main/java/redis/clients/jedis/StreamEntryID.java b/src/main/java/redis/clients/jedis/StreamEntryID.java index 873365ce56..fad28538da 100644 --- a/src/main/java/redis/clients/jedis/StreamEntryID.java +++ b/src/main/java/redis/clients/jedis/StreamEntryID.java @@ -8,56 +8,6 @@ public class StreamEntryID implements Comparable, Serializable { private static final long serialVersionUID = 1L; - /** - * Should be used only with XADD - * - * - * XADD mystream * field1 value1 - * - */ - public static final StreamEntryID NEW_ENTRY = new StreamEntryID() { - - private static final long serialVersionUID = 1L; - - @Override - public String toString() { - return "*"; - } - }; - - /** - * Should be used only with XGROUP CREATE - * - * - * XGROUP CREATE mystream consumer-group-name $ - * - */ - public static final StreamEntryID LAST_ENTRY = new StreamEntryID() { - - private static final long serialVersionUID = 1L; - - @Override - public String toString() { - return "$"; - } - }; - - /** - * Should be used only with XREADGROUP - * - * XREADGROUP $GroupName $ConsumerName BLOCK 2000 COUNT 10 STREAMS mystream > - * - */ - public static final StreamEntryID UNRECEIVED_ENTRY = new StreamEntryID() { - - private static final long serialVersionUID = 1L; - - @Override - public String toString() { - return ">"; - } - }; - private long time; private long sequence; @@ -126,4 +76,81 @@ private void readObject(java.io.ObjectInputStream in) throws IOException, ClassN this.time = in.readLong(); this.sequence = in.readLong(); } + + /** + * Should be used only with XADD + * + * + * XADD mystream * field1 value1 + * + */ + public static final StreamEntryID NEW_ENTRY = new StreamEntryID() { + + private static final long serialVersionUID = 1L; + + @Override + public String toString() { + return "*"; + } + }; + + /** + * Should be used only with XGROUP CREATE + * + * + * XGROUP CREATE mystream consumer-group-name $ + * + */ + public static final StreamEntryID LAST_ENTRY = new StreamEntryID() { + + private static final long serialVersionUID = 1L; + + @Override + public String toString() { + return "$"; + } + }; + + /** + * Should be used only with XREADGROUP + * + * + * XREADGROUP $GroupName $ConsumerName BLOCK 2000 COUNT 10 STREAMS mystream > + * + */ + public static final StreamEntryID UNRECEIVED_ENTRY = new StreamEntryID() { + + private static final long serialVersionUID = 1L; + + @Override + public String toString() { + return ">"; + } + }; + + /** + * Can be used in XRANGE, XREVRANGE and XPENDING commands. + */ + public static final StreamEntryID MINIMUM_ID = new StreamEntryID() { + + private static final long serialVersionUID = 1L; + + @Override + public String toString() { + return "-"; + } + }; + + /** + * Can be used in XRANGE, XREVRANGE and XPENDING commands. + */ + public static final StreamEntryID MAXIMUM_ID = new StreamEntryID() { + + private static final long serialVersionUID = 1L; + + @Override + public String toString() { + return "+"; + } + }; } diff --git a/src/test/java/redis/clients/jedis/commands/jedis/StreamsCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/StreamsCommandsTest.java index eb8af62b09..5336f7da71 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/StreamsCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/StreamsCommandsTest.java @@ -245,6 +245,8 @@ public void xrange() { List range8 = jedis.xrange("xrange-stream", (StreamEntryID) null, (StreamEntryID) null); assertEquals(3, range8.size()); + range8 = jedis.xrange("xrange-stream", StreamEntryID.MINIMUM_ID, StreamEntryID.MAXIMUM_ID); + assertEquals(3, range8.size()); } @Test @@ -381,6 +383,8 @@ public void xrevrange() { List range8 = jedis.xrevrange("xrevrange-stream", (StreamEntryID) null, (StreamEntryID) null); assertEquals(3, range8.size()); + range8 = jedis.xrevrange("xrevrange-stream", StreamEntryID.MAXIMUM_ID, StreamEntryID.MINIMUM_ID); + assertEquals(3, range8.size()); } @Test @@ -537,6 +541,14 @@ public void xpendingRange() { assertEquals("consumer1", response.get(0).getConsumerName()); assertEquals(m2, response.get(1).getID()); assertEquals("consumer2", response.get(1).getConsumerName()); + + response = jedis.xpending("xpendeing-stream", "xpendeing-group", + XPendingParams.xPendingParams(StreamEntryID.MINIMUM_ID, StreamEntryID.MAXIMUM_ID, 5)); + assertEquals(2, response.size()); + assertEquals(m1, response.get(0).getID()); + assertEquals("consumer1", response.get(0).getConsumerName()); + assertEquals(m2, response.get(1).getID()); + assertEquals("consumer2", response.get(1).getConsumerName()); } @Test