Skip to content

Commit

Permalink
chore: Del and NUMINCRBY use json::Path (#2655)
Browse files Browse the repository at this point in the history
* chore: Del and NUMINCRBY use json::Path

Also, fix various protocol bugs when we sent simple string
instead of sending bulk strings.

Fixed a typo in path.cc that lead to a data race bug.

Finally, flip the flag in regression tests to start covering json::Path code
and added test coverage for the data race bug

---------

Signed-off-by: Roman Gershman <[email protected]>
  • Loading branch information
romange authored Feb 26, 2024
1 parent d54f220 commit 91c299b
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 152 deletions.
13 changes: 8 additions & 5 deletions src/core/json/path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,9 @@ auto Dfs::MutateStep(const PathSegment& segment, const MutateCallback& cb, JsonT
if (segment.index() >= node->size()) {
return make_unexpected(OUT_OF_BOUNDS);
}
if (Mutate(cb, nullopt, &node[segment.index()])) {
node->erase(node->array_range().begin() + segment.index());
auto it = node->array_range().begin() + segment.index();
if (Mutate(cb, nullopt, &*it)) {
node->erase(it);
}
} break;

Expand Down Expand Up @@ -475,10 +476,12 @@ nonstd::expected<json::Path, string> ParsePath(string_view path) {
return driver.TakePath();
}

void MutatePath(const Path& path, MutateCallback callback, JsonType* json) {
unsigned MutatePath(const Path& path, MutateCallback callback, JsonType* json) {
if (path.empty())
return;
Dfs().Mutate(path, callback, json);
return 0;
Dfs dfs;
dfs.Mutate(path, callback, json);
return dfs.matches();
}

} // namespace dfly::json
4 changes: 3 additions & 1 deletion src/core/json/path.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ using PathCallback = absl::FunctionRef<void(std::optional<std::string_view>, con
using MutateCallback = absl::FunctionRef<bool(std::optional<std::string_view>, JsonType*)>;

void EvaluatePath(const Path& path, const JsonType& json, PathCallback callback);
void MutatePath(const Path& path, MutateCallback callback, JsonType* json);

// returns number of matches found with the given path.
unsigned MutatePath(const Path& path, MutateCallback callback, JsonType* json);
nonstd::expected<Path, std::string> ParsePath(std::string_view path);

} // namespace dfly::json
Loading

0 comments on commit 91c299b

Please sign in to comment.