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

Add support of new command JSON.SET and JSON.GET #1803

Merged
merged 2 commits into from
Oct 15, 2023

Conversation

PragmaTwice
Copy link
Member

@PragmaTwice PragmaTwice commented Oct 15, 2023

We add support of two new commands JSON.SET and JSON.GET (despite some options missing).

Besides, we add two new methods IsSingleKVType and IsEmptyableType to class Metadata for more intuitive coding.

JSON Metadata encoding:

key => flag | expire | format | payload

The field format is to make JSON data type more extensible. Currently it can only be 0 to indicate that the data stored in payload is in the JSON format.

TODO:

  • missing options (maybe in next PR)
  • compatible issue between jsoncons jsonpath and redis jsonpath (maybe leave as FIXME)
  • tests

Copy link
Member

@git-hulk git-hulk left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for your great work!

@git-hulk
Copy link
Member

We can create an issue to track other new commands. And others can help to implement the new commands if they like.

Copy link
Member

@mapleFU mapleFU left a comment

Choose a reason for hiding this comment

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

General it would be a good point to start, so just some nits.

jsoncons::json val;

try {
val = jsoncons::json::parse(str);
Copy link
Member

Choose a reason for hiding this comment

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

I think we'd better use parse with erroc version to avoid costing from the exception.

Copy link
Member Author

Choose a reason for hiding this comment

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

It will be fixed in later PRs, or you can pick up it if you have free time : )

Comment on lines +50 to +52
jsoncons::jsonpath::json_replace(value, path, [&new_value](const std::string & /*path*/, jsoncons::json &origin) {
origin = std::move(new_value.value);
});
Copy link
Member

Choose a reason for hiding this comment

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

Assume the path matches mutlple sub json object, this will be wrong

Copy link
Member Author

@PragmaTwice PragmaTwice Oct 15, 2023

Choose a reason for hiding this comment

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

I think since it follows preorder traversal so it will goes well when there are mutlple sub json objects matched in the original object.

But it will be wrong if there are json objects matched in the new_value, which will be fixed later.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think so, since new_value.value has been moved.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, good point. I will fix it.

@PragmaTwice
Copy link
Member Author

Tests will be added in further PRs to make an example/reference for other issues in the tracking issue : )

@PragmaTwice PragmaTwice merged commit 935f32e into apache:unstable Oct 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants