5
5
"fmt"
6
6
"strings"
7
7
8
- goredis "github.com/go-redis/redis/v8"
8
+ goredis "github.com/redis/go-redis/v9"
9
+
9
10
"github.com/nitishm/go-rejson/v4/rjs"
10
11
)
11
12
@@ -38,9 +39,9 @@ func NewGoRedisClient(ctx context.Context, conn GoRedisClientConn) *GoRedis {
38
39
// JSONSet used to set a json object
39
40
//
40
41
// ReJSON syntax:
41
- // JSON.SET <key> <path> <json>
42
- // [NX | XX]
43
42
//
43
+ // JSON.SET <key> <path> <json>
44
+ // [NX | XX]
44
45
func (r * GoRedis ) JSONSet (key string , path string , obj interface {}, opts ... rjs.SetOption ) (res interface {}, err error ) { // nolint: lll
45
46
46
47
if len (opts ) > 1 {
@@ -68,15 +69,14 @@ func (r *GoRedis) JSONSet(key string, path string, obj interface{}, opts ...rjs.
68
69
// JSONGet used to get a json object
69
70
//
70
71
// ReJSON syntax:
71
- // JSON.GET <key>
72
+ //
73
+ // JSON.GET <key>
72
74
// [INDENT indentation-string]
73
75
// [NEWLINE line-break-string]
74
76
// [SPACE space-string]
75
77
// [NOESCAPE]
76
78
// [path ...]
77
- //
78
79
func (r * GoRedis ) JSONGet (key , path string , opts ... rjs.GetOption ) (res interface {}, err error ) {
79
-
80
80
if len (opts ) > 4 {
81
81
return nil , rjs .ErrTooManyOptionals
82
82
}
@@ -103,10 +103,9 @@ func (r *GoRedis) JSONGet(key, path string, opts ...rjs.GetOption) (res interfac
103
103
// JSONMGet used to get path values from multiple keys
104
104
//
105
105
// ReJSON syntax:
106
- // JSON.MGET <key> [key ...] <path>
107
106
//
107
+ // JSON.MGET <key> [key ...] <path>
108
108
func (r * GoRedis ) JSONMGet (path string , keys ... string ) (res interface {}, err error ) {
109
-
110
109
if len (keys ) == 0 {
111
110
return nil , rjs .ErrNeedAtLeastOneArg
112
111
}
@@ -140,10 +139,9 @@ func (r *GoRedis) JSONMGet(path string, keys ...string) (res interface{}, err er
140
139
// JSONDel to delete a json object
141
140
//
142
141
// ReJSON syntax:
143
- // JSON.DEL <key> <path>
144
142
//
143
+ // JSON.DEL <key> <path>
145
144
func (r * GoRedis ) JSONDel (key string , path string ) (res interface {}, err error ) {
146
-
147
145
name , args , err := rjs .CommandBuilder (rjs .ReJSONCommandDEL , key , path )
148
146
if err != nil {
149
147
return nil , err
@@ -155,10 +153,9 @@ func (r *GoRedis) JSONDel(key string, path string) (res interface{}, err error)
155
153
// JSONType to get the type of key or member at path.
156
154
//
157
155
// ReJSON syntax:
158
- // JSON.TYPE <key> [path]
159
156
//
157
+ // JSON.TYPE <key> [path]
160
158
func (r * GoRedis ) JSONType (key , path string ) (res interface {}, err error ) {
161
-
162
159
name , args , err := rjs .CommandBuilder (rjs .ReJSONCommandTYPE , key , path )
163
160
if err != nil {
164
161
return nil , err
@@ -175,10 +172,9 @@ func (r *GoRedis) JSONType(key, path string) (res interface{}, err error) {
175
172
// JSONNumIncrBy to increment a number by provided amount
176
173
//
177
174
// ReJSON syntax:
178
- // JSON.NUMINCRBY <key> <path> <number>
179
175
//
176
+ // JSON.NUMINCRBY <key> <path> <number>
180
177
func (r * GoRedis ) JSONNumIncrBy (key , path string , number int ) (res interface {}, err error ) {
181
-
182
178
name , args , err := rjs .CommandBuilder (rjs .ReJSONCommandNUMINCRBY , key , path , number )
183
179
if err != nil {
184
180
return nil , err
@@ -194,10 +190,9 @@ func (r *GoRedis) JSONNumIncrBy(key, path string, number int) (res interface{},
194
190
// JSONNumMultBy to increment a number by provided amount
195
191
//
196
192
// ReJSON syntax:
197
- // JSON.NUMMULTBY <key> <path> <number>
198
193
//
194
+ // JSON.NUMMULTBY <key> <path> <number>
199
195
func (r * GoRedis ) JSONNumMultBy (key , path string , number int ) (res interface {}, err error ) {
200
-
201
196
name , args , err := rjs .CommandBuilder (rjs .ReJSONCommandNUMMULTBY , key , path , number )
202
197
if err != nil {
203
198
return nil , err
@@ -213,10 +208,9 @@ func (r *GoRedis) JSONNumMultBy(key, path string, number int) (res interface{},
213
208
// JSONStrAppend to append a jsonstring to an existing member
214
209
//
215
210
// ReJSON syntax:
216
- // JSON.STRAPPEND <key> [path] <json-string>
217
211
//
212
+ // JSON.STRAPPEND <key> [path] <json-string>
218
213
func (r * GoRedis ) JSONStrAppend (key , path , jsonstring string ) (res interface {}, err error ) {
219
-
220
214
name , args , err := rjs .CommandBuilder (rjs .ReJSONCommandSTRAPPEND , key , path , jsonstring )
221
215
if err != nil {
222
216
return nil , err
@@ -228,10 +222,9 @@ func (r *GoRedis) JSONStrAppend(key, path, jsonstring string) (res interface{},
228
222
// JSONStrLen to return the length of a string member
229
223
//
230
224
// ReJSON syntax:
231
- // JSON.STRLEN <key> [path]
232
225
//
226
+ // JSON.STRLEN <key> [path]
233
227
func (r * GoRedis ) JSONStrLen (key , path string ) (res interface {}, err error ) {
234
-
235
228
name , args , err := rjs .CommandBuilder (rjs .ReJSONCommandSTRLEN , key , path )
236
229
if err != nil {
237
230
return nil , err
@@ -243,10 +236,9 @@ func (r *GoRedis) JSONStrLen(key, path string) (res interface{}, err error) {
243
236
// JSONArrAppend to append json value into array at path
244
237
//
245
238
// ReJSON syntax:
246
- // JSON.ARRAPPEND <key> <path> <json> [json ...]
247
239
//
240
+ // JSON.ARRAPPEND <key> <path> <json> [json ...]
248
241
func (r * GoRedis ) JSONArrAppend (key , path string , values ... interface {}) (res interface {}, err error ) {
249
-
250
242
if len (values ) == 0 {
251
243
return nil , rjs .ErrNeedAtLeastOneArg
252
244
}
@@ -265,10 +257,9 @@ func (r *GoRedis) JSONArrAppend(key, path string, values ...interface{}) (res in
265
257
// JSONArrLen returns the length of the json array at path
266
258
//
267
259
// ReJSON syntax:
268
- // JSON.ARRLEN <key> [path]
269
260
//
261
+ // JSON.ARRLEN <key> [path]
270
262
func (r * GoRedis ) JSONArrLen (key , path string ) (res interface {}, err error ) {
271
-
272
263
name , args , err := rjs .CommandBuilder (rjs .ReJSONCommandARRLEN , key , path )
273
264
if err != nil {
274
265
return nil , err
@@ -281,10 +272,9 @@ func (r *GoRedis) JSONArrLen(key, path string) (res interface{}, err error) {
281
272
// to pop last element use rejson.PopArrLast
282
273
//
283
274
// ReJSON syntax:
284
- // JSON.ARRPOP <key> [path [index]]
285
275
//
276
+ // JSON.ARRPOP <key> [path [index]]
286
277
func (r * GoRedis ) JSONArrPop (key , path string , index int ) (res interface {}, err error ) {
287
-
288
278
name , args , err := rjs .CommandBuilder (rjs .ReJSONCommandARRPOP , key , path , index )
289
279
if err != nil {
290
280
return nil , err
@@ -301,8 +291,8 @@ func (r *GoRedis) JSONArrPop(key, path string, index int) (res interface{}, err
301
291
// JSONArrIndex returns the index of the json element provided and return -1 if element is not present
302
292
//
303
293
// ReJSON syntax:
304
- // JSON.ARRINDEX <key> <path> <json-scalar> [start [stop]]
305
294
//
295
+ // JSON.ARRINDEX <key> <path> <json-scalar> [start [stop]]
306
296
func (r * GoRedis ) JSONArrIndex (key , path string , jsonValue interface {}, optionalRange ... int ) (res interface {}, err error ) { // nolint: lll
307
297
308
298
args := []interface {}{key , path , jsonValue }
@@ -327,10 +317,9 @@ func (r *GoRedis) JSONArrIndex(key, path string, jsonValue interface{}, optional
327
317
// JSONArrTrim trims an array so that it contains only the specified inclusive range of elements
328
318
//
329
319
// ReJSON syntax:
330
- // JSON.ARRTRIM <key> <path> <start> <stop>
331
320
//
321
+ // JSON.ARRTRIM <key> <path> <start> <stop>
332
322
func (r * GoRedis ) JSONArrTrim (key , path string , start , end int ) (res interface {}, err error ) {
333
-
334
323
name , args , err := rjs .CommandBuilder (rjs .ReJSONCommandARRTRIM , key , path , start , end )
335
324
if err != nil {
336
325
return nil , err
@@ -342,10 +331,9 @@ func (r *GoRedis) JSONArrTrim(key, path string, start, end int) (res interface{}
342
331
// JSONArrInsert inserts the json value(s) into the array at path before the index (shifts to the right).
343
332
//
344
333
// ReJSON syntax:
345
- // JSON.ARRINSERT <key> <path> <index> <json> [json ...]
346
334
//
335
+ // JSON.ARRINSERT <key> <path> <index> <json> [json ...]
347
336
func (r * GoRedis ) JSONArrInsert (key , path string , index int , values ... interface {}) (res interface {}, err error ) {
348
-
349
337
if len (values ) == 0 {
350
338
return nil , rjs .ErrNeedAtLeastOneArg
351
339
}
@@ -364,10 +352,9 @@ func (r *GoRedis) JSONArrInsert(key, path string, index int, values ...interface
364
352
// JSONObjKeys returns the keys in the object that's referenced by path
365
353
//
366
354
// ReJSON syntax:
367
- // JSON.OBJKEYS <key> [path]
368
355
//
356
+ // JSON.OBJKEYS <key> [path]
369
357
func (r * GoRedis ) JSONObjKeys (key , path string ) (res interface {}, err error ) {
370
-
371
358
name , args , err := rjs .CommandBuilder (rjs .ReJSONCommandOBJKEYS , key , path )
372
359
if err != nil {
373
360
return nil , err
@@ -389,10 +376,9 @@ func (r *GoRedis) JSONObjKeys(key, path string) (res interface{}, err error) {
389
376
// JSONObjLen report the number of keys in the JSON Object at path in key
390
377
//
391
378
// ReJSON syntax:
392
- // JSON.OBJLEN <key> [path]
393
379
//
380
+ // JSON.OBJLEN <key> [path]
394
381
func (r * GoRedis ) JSONObjLen (key , path string ) (res interface {}, err error ) {
395
-
396
382
name , args , err := rjs .CommandBuilder (rjs .ReJSONCommandOBJLEN , key , path )
397
383
if err != nil {
398
384
return nil , err
@@ -404,12 +390,11 @@ func (r *GoRedis) JSONObjLen(key, path string) (res interface{}, err error) {
404
390
// JSONDebug reports information
405
391
//
406
392
// ReJSON syntax:
407
- // JSON.DEBUG <subcommand & arguments>
393
+ //
394
+ // JSON.DEBUG <subcommand & arguments>
408
395
// JSON.DEBUG MEMORY <key> [path] - report the memory usage in bytes of a value. path defaults to root if not provided.
409
396
// JSON.DEBUG HELP - reply with a helpful message
410
- //
411
397
func (r * GoRedis ) JSONDebug (subcommand rjs.DebugSubCommand , key , path string ) (res interface {}, err error ) {
412
-
413
398
if subcommand != rjs .DebugMemorySubcommand && subcommand != rjs .DebugHelpSubcommand {
414
399
err = fmt .Errorf ("unknown subcommand - try `JSON.DEBUG HELP`" )
415
400
return
@@ -439,10 +424,9 @@ func (r *GoRedis) JSONDebug(subcommand rjs.DebugSubCommand, key, path string) (r
439
424
// JSONForget is an alias for JSONDel
440
425
//
441
426
// ReJSON syntax:
442
- // JSON.FORGET <key> [path]
443
427
//
428
+ // JSON.FORGET <key> [path]
444
429
func (r * GoRedis ) JSONForget (key , path string ) (res interface {}, err error ) {
445
-
446
430
name , args , err := rjs .CommandBuilder (rjs .ReJSONCommandFORGET , key , path )
447
431
if err != nil {
448
432
return nil , err
@@ -454,10 +438,9 @@ func (r *GoRedis) JSONForget(key, path string) (res interface{}, err error) {
454
438
// JSONResp returns the JSON in key in Redis Serialization Protocol (RESP).
455
439
//
456
440
// ReJSON syntax:
457
- // JSON.RESP <key> [path]
458
441
//
442
+ // JSON.RESP <key> [path]
459
443
func (r * GoRedis ) JSONResp (key , path string ) (res interface {}, err error ) {
460
-
461
444
name , args , err := rjs .CommandBuilder (rjs .ReJSONCommandRESP , key , path )
462
445
if err != nil {
463
446
return nil , err
0 commit comments