Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion src/main/java/io/lettuce/core/RedisJsonCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Command<K, V, List<JsonValue>> jsonArrpop(K key, JsonPath jsonPath, int index) {

CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(key);

if (jsonPath != null && !jsonPath.isRootPath()) {
if (jsonPath != null) {
// OPTIONAL as per API
args.add(jsonPath.toString());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,23 @@ void shouldCorrectlyConstructJsonArrpopNoIndex() {
}

@Test
void shouldCorrectlyConstructJsonArrpopRootPath() {
void shouldCorrectlyConstructJsonArrpopRootPathNoIndex() {
Command<String, String, List<JsonValue>> command = builder.jsonArrpop(MY_KEY, JsonPath.ROOT_PATH, -1);
ByteBuf buf = Unpooled.directBuffer();
command.encode(buf);

assertThat(buf.toString(StandardCharsets.UTF_8))
.isEqualTo("*2\r\n" + "$11\r\n" + "JSON.ARRPOP\r\n" + "$15\r\n" + "bikes:inventory\r\n");
.isEqualTo("*3\r\n" + "$11\r\n" + "JSON.ARRPOP\r\n" + "$15\r\n" + "bikes:inventory\r\n" + "$1\r\n" + "$\r\n");
}

@Test
void shouldCorrectlyConstructJsonArrpopRootPath() {
Command<String, String, List<JsonValue>> command = builder.jsonArrpop(MY_KEY, JsonPath.ROOT_PATH, 1);
ByteBuf buf = Unpooled.directBuffer();
command.encode(buf);

assertThat(buf.toString(StandardCharsets.UTF_8)).isEqualTo("*4\r\n" + "$11\r\n" + "JSON.ARRPOP\r\n" + "$15\r\n"
+ "bikes:inventory\r\n" + "$1\r\n" + "$\r\n" + "$1\r\n" + "1\r\n");
}

@Test
Expand Down
12 changes: 10 additions & 2 deletions src/test/java/io/lettuce/core/json/RedisJsonIntegrationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,16 @@ public void jsonArrpopEmptyArray() {
redis.jsonSet("myKey", JsonPath.ROOT_PATH, value);
List<JsonValue> result = redis.jsonArrpop("myKey");
assertThat(result.toString()).isEqualTo("[\"one\"]");
result = redis.jsonArrpop("myKey", JsonPath.ROOT_PATH, 0);
assertThat(result.get(0).isNull()).isTrue();
assertThat(redis.jsonGet("myKey").get(0).toString()).isEqualTo("[]");
}

@Test
public void jsonArrpopWithRootPathAndIndex() {
JsonValue value = redis.getJsonParser().createJsonValue("[\"one\",\"two\",\"three\"]");
redis.jsonSet("myKey", JsonPath.ROOT_PATH, value);
List<JsonValue> result = redis.jsonArrpop("myKey", JsonPath.ROOT_PATH, 1);
assertThat(result.toString()).isEqualTo("[\"two\"]");
assertThat(redis.jsonGet("myKey").get(0).toString()).isEqualTo("[\"one\",\"three\"]");
}

@ParameterizedTest(name = "With {0} as path")
Expand Down