Skip to content
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
2 changes: 2 additions & 0 deletions src/server/json_family.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,8 @@ std::vector<std::optional<std::string>> OpJsonMGet(const WrappedJsonPath& json_p
json_val, std::move(cb), CallbackResultOptions::DefaultEvaluateOptions());

if (eval_result.IsV1()) {
if (eval_result.Empty())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be we should also return nullopt for V2. Let me check

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we now have the correct behavior:
snippet from redis:

127.0.0.1:6379> json.set json1 . '{"text":"some text"}'
OK
127.0.0.1:6379> json.set json2 . '{"text":"another text"}'
OK
127.0.0.1:6379> json.mget json1 json2 .[0]
1) (nil)
2) (nil)
127.0.0.1:6379> json.mget json1 json2 $.[0]
1) "[]"
2) "[]"

return nullopt;
return eval_result.AsV1();
}

Expand Down
11 changes: 11 additions & 0 deletions src/server/json_family_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "server/json_family.h"

#include <absl/flags/flag.h>
#include <absl/strings/str_replace.h>

#include "base/gtest.h"
Expand All @@ -16,6 +17,8 @@ using namespace testing;
using namespace std;
using namespace util;

ABSL_DECLARE_FLAG(bool, jsonpathv2);

namespace dfly {

class JsonFamilyTest : public BaseFamilyTest {
Expand Down Expand Up @@ -2547,6 +2550,14 @@ TEST_F(JsonFamilyTest, MGetLegacy) {
ASSERT_EQ(RespExpr::ARRAY, resp.type);
EXPECT_THAT(resp.GetVec(), ElementsAre(R"("Israel")", R"("Germany")", ArgType(RespExpr::NIL)));

resp = Run({"JSON.MGET", "json1", "json2", ".[0]"});
if (auto jsonpathv2 = absl::GetFlag(FLAGS_jsonpathv2); jsonpathv2) {
ASSERT_EQ(RespExpr::ARRAY, resp.type);
EXPECT_THAT(resp.GetVec(), ElementsAre(ArgType(RespExpr::NIL), ArgType(RespExpr::NIL)));
} else {
EXPECT_THAT(resp, ErrArg("ERR syntax error"));
}

resp = Run({"JSON.SET", "json3", ".", json[2]});
ASSERT_THAT(resp, "OK");

Expand Down
Loading