Skip to content

Commit be083d8

Browse files
authored
Some json command assume optional path while it's not (#3198) (#3200)
1 parent a127d5a commit be083d8

File tree

2 files changed

+236
-38
lines changed

2 files changed

+236
-38
lines changed

src/main/java/io/lettuce/core/RedisJsonCommandBuilder.java

+22-31
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Command<K, V, List<Long>> jsonArrappend(K key, JsonPath jsonPath, JsonValue... j
4747
CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(key);
4848

4949
if (jsonPath != null && !jsonPath.isRootPath()) {
50+
// OPTIONAL as per API
5051
args.add(jsonPath.toString());
5152
}
5253

@@ -62,10 +63,7 @@ Command<K, V, List<Long>> jsonArrindex(K key, JsonPath jsonPath, JsonValue value
6263

6364
CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(key);
6465

65-
if (jsonPath != null && !jsonPath.isRootPath()) {
66-
args.add(jsonPath.toString());
67-
}
68-
66+
args.add(jsonPath.toString());
6967
args.add(value.asByteBuffer().array());
7068

7169
if (range != null) {
@@ -81,10 +79,7 @@ Command<K, V, List<Long>> jsonArrinsert(K key, JsonPath jsonPath, int index, Jso
8179

8280
CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(key);
8381

84-
if (jsonPath != null && !jsonPath.isRootPath()) {
85-
args.add(jsonPath.toString());
86-
}
87-
82+
args.add(jsonPath.toString());
8883
args.add(index);
8984

9085
for (JsonValue value : values) {
@@ -100,6 +95,7 @@ Command<K, V, List<Long>> jsonArrlen(K key, JsonPath jsonPath) {
10095
CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(key);
10196

10297
if (jsonPath != null && !jsonPath.isRootPath()) {
98+
// OPTIONAL as per API
10399
args.add(jsonPath.toString());
104100
}
105101
return createCommand(JSON_ARRLEN, (CommandOutput) new ArrayOutput<>(codec), args);
@@ -110,10 +106,12 @@ Command<K, V, List<JsonValue>> jsonArrpop(K key, JsonPath jsonPath, int index) {
110106

111107
CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(key);
112108

113-
if (jsonPath != null) {
109+
if (jsonPath != null && !jsonPath.isRootPath()) {
110+
// OPTIONAL as per API
114111
args.add(jsonPath.toString());
115112

116113
if (index != -1) {
114+
// OPTIONAL as per API
117115
args.add(index);
118116
}
119117
}
@@ -126,10 +124,7 @@ Command<K, V, List<Long>> jsonArrtrim(K key, JsonPath jsonPath, JsonRangeArgs ra
126124
notNullKey(key);
127125

128126
CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(key);
129-
130-
if (jsonPath != null && !jsonPath.isRootPath()) {
131-
args.add(jsonPath.toString());
132-
}
127+
args.add(jsonPath.toString());
133128

134129
if (range != null) {
135130
range.build(args);
@@ -144,6 +139,7 @@ Command<K, V, Long> jsonClear(K key, JsonPath jsonPath) {
144139
CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(key);
145140

146141
if (jsonPath != null && !jsonPath.isRootPath()) {
142+
// OPTIONAL as per API
147143
args.add(jsonPath.toString());
148144
}
149145

@@ -156,10 +152,12 @@ Command<K, V, List<JsonValue>> jsonGet(K key, JsonGetArgs options, JsonPath... j
156152
CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(key);
157153

158154
if (options != null) {
155+
// OPTIONAL as per API
159156
options.build(args);
160157
}
161158

162159
if (jsonPaths != null) {
160+
// OPTIONAL as per API
163161
for (JsonPath jsonPath : jsonPaths) {
164162
if (jsonPath != null) {
165163
args.add(jsonPath.toString());
@@ -175,11 +173,7 @@ Command<K, V, String> jsonMerge(K key, JsonPath jsonPath, JsonValue value) {
175173
notNullKey(key);
176174

177175
CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(key);
178-
179-
if (jsonPath != null && !jsonPath.isRootPath()) {
180-
args.add(jsonPath.toString());
181-
}
182-
176+
args.add(jsonPath.toString());
183177
args.add(value.asByteBuffer().array());
184178

185179
return createCommand(JSON_MERGE, new StatusOutput<>(codec), args);
@@ -189,10 +183,7 @@ Command<K, V, List<JsonValue>> jsonMGet(JsonPath jsonPath, K... keys) {
189183
notEmpty(keys);
190184

191185
CommandArgs<K, V> args = new CommandArgs<>(codec).addKeys(keys);
192-
193-
if (jsonPath != null) {
194-
args.add(jsonPath.toString());
195-
}
186+
args.add(jsonPath.toString());
196187

197188
return createCommand(JSON_MGET, new JsonValueListOutput<>(codec, parser.get()), args);
198189
}
@@ -214,11 +205,7 @@ Command<K, V, List<Number>> jsonNumincrby(K key, JsonPath jsonPath, Number numbe
214205
notNullKey(key);
215206

216207
CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(key);
217-
218-
if (jsonPath != null && !jsonPath.isRootPath()) {
219-
args.add(jsonPath.toString());
220-
}
221-
208+
args.add(jsonPath.toString());
222209
args.add(number.toString());
223210

224211
return createCommand(JSON_NUMINCRBY, new NumberListOutput<>(codec), args);
@@ -230,6 +217,7 @@ Command<K, V, List<V>> jsonObjkeys(K key, JsonPath jsonPath) {
230217
CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(key);
231218

232219
if (jsonPath != null && !jsonPath.isRootPath()) {
220+
// OPTIONAL as per API
233221
args.add(jsonPath.toString());
234222
}
235223

@@ -243,6 +231,7 @@ Command<K, V, List<Long>> jsonObjlen(K key, JsonPath jsonPath) {
243231
CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(key);
244232

245233
if (jsonPath != null && !jsonPath.isRootPath()) {
234+
// OPTIONAL as per API
246235
args.add(jsonPath.toString());
247236
}
248237

@@ -259,6 +248,7 @@ Command<K, V, String> jsonSet(K key, JsonPath jsonPath, JsonValue value, JsonSet
259248
args.add(value.asByteBuffer().array());
260249

261250
if (options != null) {
251+
// OPTIONAL as per API
262252
options.build(args);
263253
}
264254

@@ -271,6 +261,7 @@ Command<K, V, List<Long>> jsonStrappend(K key, JsonPath jsonPath, JsonValue valu
271261
CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(key);
272262

273263
if (jsonPath != null && !jsonPath.isRootPath()) {
264+
// OPTIONAL as per API
274265
args.add(jsonPath.toString());
275266
}
276267

@@ -286,6 +277,7 @@ Command<K, V, List<Long>> jsonStrlen(K key, JsonPath jsonPath) {
286277
CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(key);
287278

288279
if (jsonPath != null && !jsonPath.isRootPath()) {
280+
// OPTIONAL as per API
289281
args.add(jsonPath.toString());
290282
}
291283

@@ -296,10 +288,7 @@ Command<K, V, List<Long>> jsonToggle(K key, JsonPath jsonPath) {
296288
notNullKey(key);
297289

298290
CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(key);
299-
300-
if (jsonPath != null && !jsonPath.isRootPath()) {
301-
args.add(jsonPath.toString());
302-
}
291+
args.add(jsonPath.toString());
303292

304293
return createCommand(JSON_TOGGLE, (CommandOutput) new ArrayOutput<>(codec), args);
305294
}
@@ -310,6 +299,7 @@ Command<K, V, Long> jsonDel(K key, JsonPath jsonPath) {
310299
CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(key);
311300

312301
if (jsonPath != null && !jsonPath.isRootPath()) {
302+
// OPTIONAL as per API
313303
args.add(jsonPath.toString());
314304
}
315305
return createCommand(JSON_DEL, new IntegerOutput<>(codec), args);
@@ -321,6 +311,7 @@ Command<K, V, List<JsonType>> jsonType(K key, JsonPath jsonPath) {
321311
CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(key);
322312

323313
if (jsonPath != null && !jsonPath.isRootPath()) {
314+
// OPTIONAL as per API
324315
args.add(jsonPath.toString());
325316
}
326317

0 commit comments

Comments
 (0)