55 "fmt"
66 "strings"
77
8- goredis "github.com/go-redis/redis/v8"
8+ goredis "github.com/redis/go-redis/v9"
9+
910 "github.com/nitishm/go-rejson/v4/rjs"
1011)
1112
@@ -38,9 +39,9 @@ func NewGoRedisClient(ctx context.Context, conn GoRedisClientConn) *GoRedis {
3839// JSONSet used to set a json object
3940//
4041// ReJSON syntax:
41- // JSON.SET <key> <path> <json>
42- // [NX | XX]
4342//
43+ // JSON.SET <key> <path> <json>
44+ // [NX | XX]
4445func (r * GoRedis ) JSONSet (key string , path string , obj interface {}, opts ... rjs.SetOption ) (res interface {}, err error ) { // nolint: lll
4546
4647 if len (opts ) > 1 {
@@ -68,15 +69,14 @@ func (r *GoRedis) JSONSet(key string, path string, obj interface{}, opts ...rjs.
6869// JSONGet used to get a json object
6970//
7071// ReJSON syntax:
71- // JSON.GET <key>
72+ //
73+ // JSON.GET <key>
7274// [INDENT indentation-string]
7375// [NEWLINE line-break-string]
7476// [SPACE space-string]
7577// [NOESCAPE]
7678// [path ...]
77- //
7879func (r * GoRedis ) JSONGet (key , path string , opts ... rjs.GetOption ) (res interface {}, err error ) {
79-
8080 if len (opts ) > 4 {
8181 return nil , rjs .ErrTooManyOptionals
8282 }
@@ -103,10 +103,9 @@ func (r *GoRedis) JSONGet(key, path string, opts ...rjs.GetOption) (res interfac
103103// JSONMGet used to get path values from multiple keys
104104//
105105// ReJSON syntax:
106- // JSON.MGET <key> [key ...] <path>
107106//
107+ // JSON.MGET <key> [key ...] <path>
108108func (r * GoRedis ) JSONMGet (path string , keys ... string ) (res interface {}, err error ) {
109-
110109 if len (keys ) == 0 {
111110 return nil , rjs .ErrNeedAtLeastOneArg
112111 }
@@ -140,10 +139,9 @@ func (r *GoRedis) JSONMGet(path string, keys ...string) (res interface{}, err er
140139// JSONDel to delete a json object
141140//
142141// ReJSON syntax:
143- // JSON.DEL <key> <path>
144142//
143+ // JSON.DEL <key> <path>
145144func (r * GoRedis ) JSONDel (key string , path string ) (res interface {}, err error ) {
146-
147145 name , args , err := rjs .CommandBuilder (rjs .ReJSONCommandDEL , key , path )
148146 if err != nil {
149147 return nil , err
@@ -155,10 +153,9 @@ func (r *GoRedis) JSONDel(key string, path string) (res interface{}, err error)
155153// JSONType to get the type of key or member at path.
156154//
157155// ReJSON syntax:
158- // JSON.TYPE <key> [path]
159156//
157+ // JSON.TYPE <key> [path]
160158func (r * GoRedis ) JSONType (key , path string ) (res interface {}, err error ) {
161-
162159 name , args , err := rjs .CommandBuilder (rjs .ReJSONCommandTYPE , key , path )
163160 if err != nil {
164161 return nil , err
@@ -175,10 +172,9 @@ func (r *GoRedis) JSONType(key, path string) (res interface{}, err error) {
175172// JSONNumIncrBy to increment a number by provided amount
176173//
177174// ReJSON syntax:
178- // JSON.NUMINCRBY <key> <path> <number>
179175//
176+ // JSON.NUMINCRBY <key> <path> <number>
180177func (r * GoRedis ) JSONNumIncrBy (key , path string , number int ) (res interface {}, err error ) {
181-
182178 name , args , err := rjs .CommandBuilder (rjs .ReJSONCommandNUMINCRBY , key , path , number )
183179 if err != nil {
184180 return nil , err
@@ -194,10 +190,9 @@ func (r *GoRedis) JSONNumIncrBy(key, path string, number int) (res interface{},
194190// JSONNumMultBy to increment a number by provided amount
195191//
196192// ReJSON syntax:
197- // JSON.NUMMULTBY <key> <path> <number>
198193//
194+ // JSON.NUMMULTBY <key> <path> <number>
199195func (r * GoRedis ) JSONNumMultBy (key , path string , number int ) (res interface {}, err error ) {
200-
201196 name , args , err := rjs .CommandBuilder (rjs .ReJSONCommandNUMMULTBY , key , path , number )
202197 if err != nil {
203198 return nil , err
@@ -213,10 +208,9 @@ func (r *GoRedis) JSONNumMultBy(key, path string, number int) (res interface{},
213208// JSONStrAppend to append a jsonstring to an existing member
214209//
215210// ReJSON syntax:
216- // JSON.STRAPPEND <key> [path] <json-string>
217211//
212+ // JSON.STRAPPEND <key> [path] <json-string>
218213func (r * GoRedis ) JSONStrAppend (key , path , jsonstring string ) (res interface {}, err error ) {
219-
220214 name , args , err := rjs .CommandBuilder (rjs .ReJSONCommandSTRAPPEND , key , path , jsonstring )
221215 if err != nil {
222216 return nil , err
@@ -228,10 +222,9 @@ func (r *GoRedis) JSONStrAppend(key, path, jsonstring string) (res interface{},
228222// JSONStrLen to return the length of a string member
229223//
230224// ReJSON syntax:
231- // JSON.STRLEN <key> [path]
232225//
226+ // JSON.STRLEN <key> [path]
233227func (r * GoRedis ) JSONStrLen (key , path string ) (res interface {}, err error ) {
234-
235228 name , args , err := rjs .CommandBuilder (rjs .ReJSONCommandSTRLEN , key , path )
236229 if err != nil {
237230 return nil , err
@@ -243,10 +236,9 @@ func (r *GoRedis) JSONStrLen(key, path string) (res interface{}, err error) {
243236// JSONArrAppend to append json value into array at path
244237//
245238// ReJSON syntax:
246- // JSON.ARRAPPEND <key> <path> <json> [json ...]
247239//
240+ // JSON.ARRAPPEND <key> <path> <json> [json ...]
248241func (r * GoRedis ) JSONArrAppend (key , path string , values ... interface {}) (res interface {}, err error ) {
249-
250242 if len (values ) == 0 {
251243 return nil , rjs .ErrNeedAtLeastOneArg
252244 }
@@ -265,10 +257,9 @@ func (r *GoRedis) JSONArrAppend(key, path string, values ...interface{}) (res in
265257// JSONArrLen returns the length of the json array at path
266258//
267259// ReJSON syntax:
268- // JSON.ARRLEN <key> [path]
269260//
261+ // JSON.ARRLEN <key> [path]
270262func (r * GoRedis ) JSONArrLen (key , path string ) (res interface {}, err error ) {
271-
272263 name , args , err := rjs .CommandBuilder (rjs .ReJSONCommandARRLEN , key , path )
273264 if err != nil {
274265 return nil , err
@@ -281,10 +272,9 @@ func (r *GoRedis) JSONArrLen(key, path string) (res interface{}, err error) {
281272// to pop last element use rejson.PopArrLast
282273//
283274// ReJSON syntax:
284- // JSON.ARRPOP <key> [path [index]]
285275//
276+ // JSON.ARRPOP <key> [path [index]]
286277func (r * GoRedis ) JSONArrPop (key , path string , index int ) (res interface {}, err error ) {
287-
288278 name , args , err := rjs .CommandBuilder (rjs .ReJSONCommandARRPOP , key , path , index )
289279 if err != nil {
290280 return nil , err
@@ -301,8 +291,8 @@ func (r *GoRedis) JSONArrPop(key, path string, index int) (res interface{}, err
301291// JSONArrIndex returns the index of the json element provided and return -1 if element is not present
302292//
303293// ReJSON syntax:
304- // JSON.ARRINDEX <key> <path> <json-scalar> [start [stop]]
305294//
295+ // JSON.ARRINDEX <key> <path> <json-scalar> [start [stop]]
306296func (r * GoRedis ) JSONArrIndex (key , path string , jsonValue interface {}, optionalRange ... int ) (res interface {}, err error ) { // nolint: lll
307297
308298 args := []interface {}{key , path , jsonValue }
@@ -327,10 +317,9 @@ func (r *GoRedis) JSONArrIndex(key, path string, jsonValue interface{}, optional
327317// JSONArrTrim trims an array so that it contains only the specified inclusive range of elements
328318//
329319// ReJSON syntax:
330- // JSON.ARRTRIM <key> <path> <start> <stop>
331320//
321+ // JSON.ARRTRIM <key> <path> <start> <stop>
332322func (r * GoRedis ) JSONArrTrim (key , path string , start , end int ) (res interface {}, err error ) {
333-
334323 name , args , err := rjs .CommandBuilder (rjs .ReJSONCommandARRTRIM , key , path , start , end )
335324 if err != nil {
336325 return nil , err
@@ -342,10 +331,9 @@ func (r *GoRedis) JSONArrTrim(key, path string, start, end int) (res interface{}
342331// JSONArrInsert inserts the json value(s) into the array at path before the index (shifts to the right).
343332//
344333// ReJSON syntax:
345- // JSON.ARRINSERT <key> <path> <index> <json> [json ...]
346334//
335+ // JSON.ARRINSERT <key> <path> <index> <json> [json ...]
347336func (r * GoRedis ) JSONArrInsert (key , path string , index int , values ... interface {}) (res interface {}, err error ) {
348-
349337 if len (values ) == 0 {
350338 return nil , rjs .ErrNeedAtLeastOneArg
351339 }
@@ -364,10 +352,9 @@ func (r *GoRedis) JSONArrInsert(key, path string, index int, values ...interface
364352// JSONObjKeys returns the keys in the object that's referenced by path
365353//
366354// ReJSON syntax:
367- // JSON.OBJKEYS <key> [path]
368355//
356+ // JSON.OBJKEYS <key> [path]
369357func (r * GoRedis ) JSONObjKeys (key , path string ) (res interface {}, err error ) {
370-
371358 name , args , err := rjs .CommandBuilder (rjs .ReJSONCommandOBJKEYS , key , path )
372359 if err != nil {
373360 return nil , err
@@ -389,10 +376,9 @@ func (r *GoRedis) JSONObjKeys(key, path string) (res interface{}, err error) {
389376// JSONObjLen report the number of keys in the JSON Object at path in key
390377//
391378// ReJSON syntax:
392- // JSON.OBJLEN <key> [path]
393379//
380+ // JSON.OBJLEN <key> [path]
394381func (r * GoRedis ) JSONObjLen (key , path string ) (res interface {}, err error ) {
395-
396382 name , args , err := rjs .CommandBuilder (rjs .ReJSONCommandOBJLEN , key , path )
397383 if err != nil {
398384 return nil , err
@@ -404,12 +390,11 @@ func (r *GoRedis) JSONObjLen(key, path string) (res interface{}, err error) {
404390// JSONDebug reports information
405391//
406392// ReJSON syntax:
407- // JSON.DEBUG <subcommand & arguments>
393+ //
394+ // JSON.DEBUG <subcommand & arguments>
408395// JSON.DEBUG MEMORY <key> [path] - report the memory usage in bytes of a value. path defaults to root if not provided.
409396// JSON.DEBUG HELP - reply with a helpful message
410- //
411397func (r * GoRedis ) JSONDebug (subcommand rjs.DebugSubCommand , key , path string ) (res interface {}, err error ) {
412-
413398 if subcommand != rjs .DebugMemorySubcommand && subcommand != rjs .DebugHelpSubcommand {
414399 err = fmt .Errorf ("unknown subcommand - try `JSON.DEBUG HELP`" )
415400 return
@@ -439,10 +424,9 @@ func (r *GoRedis) JSONDebug(subcommand rjs.DebugSubCommand, key, path string) (r
439424// JSONForget is an alias for JSONDel
440425//
441426// ReJSON syntax:
442- // JSON.FORGET <key> [path]
443427//
428+ // JSON.FORGET <key> [path]
444429func (r * GoRedis ) JSONForget (key , path string ) (res interface {}, err error ) {
445-
446430 name , args , err := rjs .CommandBuilder (rjs .ReJSONCommandFORGET , key , path )
447431 if err != nil {
448432 return nil , err
@@ -454,10 +438,9 @@ func (r *GoRedis) JSONForget(key, path string) (res interface{}, err error) {
454438// JSONResp returns the JSON in key in Redis Serialization Protocol (RESP).
455439//
456440// ReJSON syntax:
457- // JSON.RESP <key> [path]
458441//
442+ // JSON.RESP <key> [path]
459443func (r * GoRedis ) JSONResp (key , path string ) (res interface {}, err error ) {
460-
461444 name , args , err := rjs .CommandBuilder (rjs .ReJSONCommandRESP , key , path )
462445 if err != nil {
463446 return nil , err
0 commit comments