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 authored Aug 22, 2024
1 parent 2a43ab5 commit 3b6b2b0
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 @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down

0 comments on commit 3b6b2b0

Please sign in to comment.