Skip to content

Commit

Permalink
Accept null replies for BZPOPMAX and BZPOPMIN commands (#3930)
Browse files Browse the repository at this point in the history
  • Loading branch information
sazzad16 committed Aug 22, 2024
1 parent be6cec8 commit f60814a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/main/java/redis/clients/jedis/BuilderFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -598,10 +598,9 @@ public String toString() {
@Override
@SuppressWarnings("unchecked")
public KeyValue<String, Tuple> build(Object data) {
List<Object> l = (List<Object>) data; // never null
if (l.isEmpty()) {
return null;
}
if (data == null) return null;
List<Object> l = (List<Object>) 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))));
}

Expand All @@ -615,10 +614,9 @@ public String toString() {
@Override
@SuppressWarnings("unchecked")
public KeyValue<byte[], Tuple> build(Object data) {
List<Object> l = (List<Object>) data; // never null
if (l.isEmpty()) {
return null;
}
if (data == null) return null;
List<Object> l = (List<Object>) 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))));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1519,12 +1519,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);
Expand All @@ -1535,12 +1539,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1508,12 +1508,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);
Expand All @@ -1524,12 +1528,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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//package redis.clients.jedis.commands.unified.cluster;
//
//import static org.junit.Assert.assertEquals;
//import static org.junit.Assert.assertNull;
//
//import java.util.ArrayList;
//import java.util.Collections;
Expand Down Expand Up @@ -148,6 +149,8 @@
// @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());
Expand All @@ -157,6 +160,8 @@
// @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());
Expand Down

0 comments on commit f60814a

Please sign in to comment.