From 69c7e836c7869696aee106cc00782a5d077a3c96 Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Thu, 22 Aug 2024 00:08:27 +0600 Subject: [PATCH] Accept null replies for BZPOPMAX and BZPOPMIN commands --- .../java/redis/clients/jedis/BuilderFactory.java | 14 ++++++-------- .../commands/jedis/SortedSetCommandsTest.java | 8 ++++++++ .../unified/SortedSetCommandsTestBase.java | 8 ++++++++ .../cluster/ClusterSortedSetCommandsTest.java | 5 +++++ 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BuilderFactory.java b/src/main/java/redis/clients/jedis/BuilderFactory.java index a48168357d..adce27f1f4 100644 --- a/src/main/java/redis/clients/jedis/BuilderFactory.java +++ b/src/main/java/redis/clients/jedis/BuilderFactory.java @@ -598,10 +598,9 @@ public String toString() { @Override @SuppressWarnings("unchecked") public KeyValue build(Object data) { - List l = (List) data; // never null - if (l.isEmpty()) { - return null; - } + if (data == null) return null; + List l = (List) data; + if (l.isEmpty()) return null; return KeyValue.of(STRING.build(l.get(0)), new Tuple(BINARY.build(l.get(1)), DOUBLE.build(l.get(2)))); } @@ -615,10 +614,9 @@ public String toString() { @Override @SuppressWarnings("unchecked") public KeyValue build(Object data) { - List l = (List) data; // never null - if (l.isEmpty()) { - return null; - } + if (data == null) return null; + List l = (List) data; + if (l.isEmpty()) return null; return KeyValue.of(BINARY.build(l.get(0)), new Tuple(BINARY.build(l.get(1)), DOUBLE.build(l.get(2)))); } diff --git a/src/test/java/redis/clients/jedis/commands/jedis/SortedSetCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/SortedSetCommandsTest.java index 6860684028..9e4cd71a53 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/SortedSetCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/SortedSetCommandsTest.java @@ -1527,12 +1527,16 @@ public void infinity() { @Test public void bzpopmax() { + assertNull(jedis.bzpopmax(1, "foo", "bar")); + jedis.zadd("foo", 1d, "a", ZAddParams.zAddParams().nx()); jedis.zadd("foo", 10d, "b", ZAddParams.zAddParams().nx()); jedis.zadd("bar", 0.1d, "c", ZAddParams.zAddParams().nx()); assertEquals(new KeyValue<>("foo", new Tuple("b", 10d)), jedis.bzpopmax(0, "foo", "bar")); // Binary + assertNull(jedis.bzpopmax(1, bfoo, bbar)); + jedis.zadd(bfoo, 1d, ba); jedis.zadd(bfoo, 10d, bb); jedis.zadd(bbar, 0.1d, bc); @@ -1543,12 +1547,16 @@ public void bzpopmax() { @Test public void bzpopmin() { + assertNull(jedis.bzpopmin(1, "bar", "foo")); + jedis.zadd("foo", 1d, "a", ZAddParams.zAddParams().nx()); jedis.zadd("foo", 10d, "b", ZAddParams.zAddParams().nx()); jedis.zadd("bar", 0.1d, "c", ZAddParams.zAddParams().nx()); assertEquals(new KeyValue<>("bar", new Tuple("c", 0.1)), jedis.bzpopmin(0, "bar", "foo")); // Binary + assertNull(jedis.bzpopmin(1, bbar, bfoo)); + jedis.zadd(bfoo, 1d, ba); jedis.zadd(bfoo, 10d, bb); jedis.zadd(bbar, 0.1d, bc); diff --git a/src/test/java/redis/clients/jedis/commands/unified/SortedSetCommandsTestBase.java b/src/test/java/redis/clients/jedis/commands/unified/SortedSetCommandsTestBase.java index 3f56a91459..126a884993 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/SortedSetCommandsTestBase.java +++ b/src/test/java/redis/clients/jedis/commands/unified/SortedSetCommandsTestBase.java @@ -1513,12 +1513,16 @@ public void infinity() { @Test public void bzpopmax() { + assertNull(jedis.bzpopmax(1, "foo", "bar")); + jedis.zadd("foo", 1d, "a", ZAddParams.zAddParams().nx()); jedis.zadd("foo", 10d, "b", ZAddParams.zAddParams().nx()); jedis.zadd("bar", 0.1d, "c", ZAddParams.zAddParams().nx()); assertEquals(new KeyValue<>("foo", new Tuple("b", 10d)), jedis.bzpopmax(0, "foo", "bar")); // Binary + assertNull(jedis.bzpopmax(1, bfoo, bbar)); + jedis.zadd(bfoo, 1d, ba); jedis.zadd(bfoo, 10d, bb); jedis.zadd(bbar, 0.1d, bc); @@ -1529,12 +1533,16 @@ public void bzpopmax() { @Test public void bzpopmin() { + assertNull(jedis.bzpopmin(1, "bar", "foo")); + jedis.zadd("foo", 1d, "a", ZAddParams.zAddParams().nx()); jedis.zadd("foo", 10d, "b", ZAddParams.zAddParams().nx()); jedis.zadd("bar", 0.1d, "c", ZAddParams.zAddParams().nx()); assertEquals(new KeyValue<>("bar", new Tuple("c", 0.1)), jedis.bzpopmin(0, "bar", "foo")); // Binary + assertNull(jedis.bzpopmin(1, bbar, bfoo)); + jedis.zadd(bfoo, 1d, ba); jedis.zadd(bfoo, 10d, bb); jedis.zadd(bbar, 0.1d, bc); diff --git a/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterSortedSetCommandsTest.java b/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterSortedSetCommandsTest.java index 9151b0c52b..b08d7b1773 100644 --- a/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterSortedSetCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterSortedSetCommandsTest.java @@ -3,6 +3,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import static redis.clients.jedis.util.AssertUtil.assertByteArrayListEquals; import java.util.ArrayList; @@ -154,6 +155,8 @@ public void zintertoreParams() { @Test @Override public void bzpopmax() { + assertNull(jedis.bzpopmax(1, "f{:}oo", "b{:}ar")); + jedis.zadd("f{:}oo", 1d, "a", ZAddParams.zAddParams().nx()); jedis.zadd("f{:}oo", 10d, "b", ZAddParams.zAddParams().nx()); jedis.zadd("b{:}ar", 0.1d, "c", ZAddParams.zAddParams().nx()); @@ -163,6 +166,8 @@ public void bzpopmax() { @Test @Override public void bzpopmin() { + assertNull(jedis.bzpopmin(1, "ba{:}r", "fo{:}o")); + jedis.zadd("fo{:}o", 1d, "a", ZAddParams.zAddParams().nx()); jedis.zadd("fo{:}o", 10d, "b", ZAddParams.zAddParams().nx()); jedis.zadd("ba{:}r", 0.1d, "c", ZAddParams.zAddParams().nx());