Fix LPOS when member not in list.
This commit ensures an empty List is returned in the case the member does not exist in the target list. See #1957. Original pull request: #1962.
This commit is contained in:
committed by
Mark Paluch
parent
19eb0930cd
commit
840c7f50ca
@@ -72,7 +72,7 @@ class JedisListCommands implements RedisListCommands {
|
||||
return connection.invoke().just(BinaryJedis::lpos, MultiKeyPipelineBase::lpos, key, element, params, count);
|
||||
}
|
||||
|
||||
return connection.invoke().from(BinaryJedis::lpos, MultiKeyPipelineBase::lpos, key, element, params).get(Collections::singletonList);
|
||||
return connection.invoke().from(BinaryJedis::lpos, MultiKeyPipelineBase::lpos, key, element, params).getOrElse(Collections::singletonList, Collections::emptyList);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -71,7 +71,7 @@ class LettuceListCommands implements RedisListCommands {
|
||||
return connection.invoke().just(RedisListAsyncCommands::lpos, key, element, count, args);
|
||||
}
|
||||
|
||||
return connection.invoke().from(RedisListAsyncCommands::lpos, key, element, args).get(Collections::singletonList);
|
||||
return connection.invoke().from(RedisListAsyncCommands::lpos, key, element, args).getOrElse(Collections::singletonList, Collections::emptyList);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -1464,6 +1464,16 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
assertThat((List<Long>) getResults().get(1)).containsExactly(2L, 6L, 7L);
|
||||
}
|
||||
|
||||
@Test // GH-1957
|
||||
@EnabledOnCommand("LPOS")
|
||||
void lPosNonExisting() {
|
||||
|
||||
actual.add(connection.rPush("mylist", "a", "b", "c", "1", "2", "3", "c", "c"));
|
||||
actual.add(connection.lPos("mylist", "x", null, null));
|
||||
|
||||
assertThat((List<Long>) getResults().get(1)).isEmpty();
|
||||
}
|
||||
|
||||
// Set operations
|
||||
|
||||
@Test
|
||||
|
||||
@@ -2534,4 +2534,14 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
|
||||
assertThat(result).containsExactly(2L, 6L, 7L);
|
||||
}
|
||||
|
||||
@Test // GH-1957
|
||||
@EnabledOnCommand("LPOS")
|
||||
void lPosNonExisting() {
|
||||
|
||||
nativeConnection.rpush(KEY_1, "a", "b", "c", "1", "2", "3", "c", "c");
|
||||
List<Long> result = clusterConnection.listCommands().lPos(KEY_1_BYTES, "x".getBytes(StandardCharsets.UTF_8), null, null);
|
||||
|
||||
assertThat(result).isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user