Skip to content

Commit 5877684

Browse files
rigazillaCrumby
authored andcommitted
[#16223] RESP JSON.MGET fixed arity check
1 parent 22d4765 commit 5877684

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

server/resp/src/main/java/org/infinispan/server/resp/commands/json/JSONMGET.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ public JSONMGET() {
3232
@Override
3333
public CompletionStage<RespRequestHandler> perform(Resp3Handler handler, ChannelHandlerContext ctx,
3434
List<byte[]> arguments) {
35-
if (arguments.size() < 3) {
36-
handler.writer().wrongArgumentNumber(this);
37-
return handler.myStage();
38-
}
3935
List<byte[]> keys = arguments.subList(0, arguments.size() - 1);
4036
// Getting path as list to match get() signature
4137
List<byte[]> paths = arguments.subList(arguments.size() - 1, arguments.size());

server/resp/src/test/java/org/infinispan/server/resp/JsonCommandsTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,6 +1894,22 @@ public void testJSONMGET() {
18941894
// var result = redis.jsonMGet(jpRoot, "not-a-json", key1, key2);
18951895
}
18961896

1897+
@Test
1898+
public void testJSONMGETSingleKey() {
1899+
// Test for issue #16223: JSON.MGET should accept single key
1900+
String key1 = k();
1901+
JsonPath jpRoot = new JsonPath("$");
1902+
JsonValue jv1 = defaultJsonParser.createJsonValue("""
1903+
{"a":1, "b": 2, "nested": {"a": 3}, "c": null}
1904+
""");
1905+
redis.jsonSet(key1, jpRoot, jv1);
1906+
1907+
// Test with single key and JSONPath
1908+
List<JsonValue> result = redis.jsonMGet(new JsonPath("$..a"), key1);
1909+
assertThat(result).hasSize(1);
1910+
assertThat(result.get(0).toString()).isEqualTo("[1,3]");
1911+
}
1912+
18971913
// Lettuce Json object doesn't implement comparison. Implementing here
18981914
private boolean compareJSONGet(JsonValue result, JsonValue expected, JsonPath... paths) {
18991915
ObjectMapper mapper = new ObjectMapper();

0 commit comments

Comments
 (0)