|
20 | 20 | #include "core/json/json_object.h"
|
21 | 21 | #include "core/json/path.h"
|
22 | 22 | #include "facade/cmd_arg_parser.h"
|
23 |
| -#include "facade/error.h" |
24 | 23 | #include "facade/op_status.h"
|
25 | 24 | #include "server/acl/acl_commands_def.h"
|
26 | 25 | #include "server/command_registry.h"
|
@@ -109,49 +108,53 @@ ParseResult<WrappedJsonPath> ParseJsonPath(std::string_view path) {
|
109 | 108 |
|
110 | 109 | namespace reply_generic {
|
111 | 110 |
|
112 |
| -template <typename T> void Send(RedisReplyBuilder& rb, T value) = delete; |
| 111 | +template <typename T> void Send(T value, RedisReplyBuilder* rb) = delete; |
113 | 112 |
|
114 |
| -template <> void Send(RedisReplyBuilder& rb, std::size_t value) { |
115 |
| - rb.SendLong(value); |
| 113 | +template <> void Send(std::size_t value, RedisReplyBuilder* rb) { |
| 114 | + rb->SendLong(value); |
116 | 115 | }
|
117 | 116 |
|
118 |
| -template <typename T> void Send(RedisReplyBuilder& rb, const std::optional<T>& opt) { |
| 117 | +template <typename T> void Send(const std::optional<T>& opt, RedisReplyBuilder* rb) { |
119 | 118 | if (opt.has_value()) {
|
120 |
| - Send(rb, opt.value()); |
| 119 | + Send(opt.value(), rb); |
121 | 120 | } else {
|
122 |
| - rb.SendNull(); |
| 121 | + rb->SendNull(); |
123 | 122 | }
|
124 | 123 | }
|
125 | 124 |
|
126 |
| -template <typename T> void Send(RedisReplyBuilder& rb, const std::vector<T>& vec) { |
| 125 | +template <typename T> void Send(const std::vector<T>& vec, RedisReplyBuilder* rb) { |
127 | 126 | if (vec.empty()) {
|
128 |
| - rb.SendNullArray(); |
| 127 | + rb->SendNullArray(); |
129 | 128 | } else {
|
130 |
| - rb.StartArray(vec.size()); |
| 129 | + rb->StartArray(vec.size()); |
131 | 130 | for (auto&& x : vec) {
|
132 |
| - Send(rb, x); |
| 131 | + Send(x, rb); |
133 | 132 | }
|
134 | 133 | }
|
135 | 134 | }
|
136 | 135 |
|
137 |
| -template <typename T> void Send(RedisReplyBuilder& rb, JsonCallbackResult<T>& result) { |
| 136 | +template <typename T> void Send(const JsonCallbackResult<T>& result, RedisReplyBuilder* rb) { |
138 | 137 | if (result.error_code) {
|
139 |
| - rb.SendError(result.error_code.message(), kSyntaxErrType); // todo edit |
| 138 | + rb->SendError(result.error_code.message()); |
140 | 139 | return;
|
141 | 140 | }
|
142 | 141 |
|
143 | 142 | if (result.IsV1()) {
|
144 |
| - Send(rb, result.AsV1()); |
| 143 | + /* The specified path was restricted (JSON legacy mode), then the result consists only of a |
| 144 | + * single value */ |
| 145 | + Send(result.AsV1(), rb); |
145 | 146 | } else {
|
146 |
| - Send(rb, result.AsV2()); |
| 147 | + /* The specified path was enhanced (starts with '$'), then the result is an array of multiple |
| 148 | + * values */ |
| 149 | + Send(result.AsV2(), rb); |
147 | 150 | }
|
148 | 151 | }
|
149 | 152 |
|
150 |
| -template <typename T> void Send(RedisReplyBuilder& rb, OpResult<T>& result) { |
| 153 | +template <typename T> void Send(const OpResult<T>& result, RedisReplyBuilder* rb) { |
151 | 154 | if (result) {
|
152 |
| - Send(rb, result.value()); |
| 155 | + Send(result.value(), rb); |
153 | 156 | } else {
|
154 |
| - rb.SendError(result.status()); |
| 157 | + rb->SendError(result.status()); |
155 | 158 | }
|
156 | 159 | }
|
157 | 160 |
|
@@ -1965,7 +1968,7 @@ void JsonFamily::StrAppend(CmdArgList args, ConnectionContext* cntx) {
|
1965 | 1968 | Transaction* trans = cntx->transaction;
|
1966 | 1969 | auto result = trans->ScheduleSingleHopT(std::move(cb));
|
1967 | 1970 | auto* rb = static_cast<RedisReplyBuilder*>(cntx->reply_builder());
|
1968 |
| - reply_generic::Send(*rb, result); |
| 1971 | + reply_generic::Send(result, rb); |
1969 | 1972 | }
|
1970 | 1973 |
|
1971 | 1974 | void JsonFamily::ObjKeys(CmdArgList args, ConnectionContext* cntx) {
|
|
0 commit comments