Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept null replies for BZPOPMAX and BZPOPMIN commands #3930

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading