From d2aa875760e4d37ba15d67270d5b20b44d3f19a5 Mon Sep 17 00:00:00 2001 From: Yafim Kazak Date: Fri, 31 Mar 2023 09:02:35 +0300 Subject: [PATCH] add support for redis v9 (#72) * add support for redis v9 * fix workflow * Update .github/workflows/test.yml * Fix versioning issues in ci-workflows * Upgrade golangci-lint and staticcheck-action Ref golangci/golangci-lint#3107 * remove deprecated command from examples * gofmt'ed --------- Co-authored-by: Shivam Rathore <29069530+Shivam010@users.noreply.github.com> --- .github/workflows/analysis.yml | 15 +++-- .github/workflows/test.yml | 11 ++-- clients/goredis.go | 67 +++++++------------ clients/redigo.go | 68 +++++++------------ doc.go | 13 ++-- examples/json_array/json_array.go | 5 +- examples/json_obj/json_obj.go | 4 +- examples/json_set/json_set.go | 5 +- go.mod | 2 +- go.sum | 104 ++++++------------------------ rejson.go | 54 ++++++++-------- rejson_test.go | 2 +- rjs/commands.go | 2 +- rjs/options.go | 13 ++-- set_client.go | 2 +- 15 files changed, 134 insertions(+), 233 deletions(-) diff --git a/.github/workflows/analysis.yml b/.github/workflows/analysis.yml index 8f7fbb3..8eded2e 100644 --- a/.github/workflows/analysis.yml +++ b/.github/workflows/analysis.yml @@ -9,14 +9,19 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v2 with: - version: v1.35 + version: v1.51.2 staticcheck: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: check - uses: grandcolline/golang-github-actions@v1.1.0 + - name: set up go + uses: actions/setup-go@v4 with: - run: staticcheck - token: ${{ secrets.GITHUB_TOKEN }} + go-version: '>=1.17.0' + id: go + - name: staticcheck + uses: dominikh/staticcheck-action@v1.2.0 + with: + version: "2023.1.3" + install-go: false diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4f8b55b..0a5ee60 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,10 +4,6 @@ on: [push, pull_request] jobs: test: runs-on: ubuntu-latest - strategy: - matrix: - go_version: [ 1.13, 1.14, 1.15 ] - services: redis-rejson: image: redislabs/rejson:1.0.8 @@ -21,11 +17,12 @@ jobs: steps: - uses: actions/checkout@v2 - - name: set up go ${{ matrix.go_version }} - uses: actions/setup-go@v2 + - name: set up go + uses: actions/setup-go@v4 with: - go-version: ${{ matrix.go_version }} + go-version: '>=1.17.0' id: go + - run: "go vet ./..." - name: go test run: | go test -race -v -covermode=atomic -coverprofile=profile.cov ./... diff --git a/clients/goredis.go b/clients/goredis.go index d3f454b..3ae2260 100644 --- a/clients/goredis.go +++ b/clients/goredis.go @@ -5,7 +5,8 @@ import ( "fmt" "strings" - goredis "github.com/go-redis/redis/v8" + goredis "github.com/redis/go-redis/v9" + "github.com/nitishm/go-rejson/v4/rjs" ) @@ -38,9 +39,9 @@ func NewGoRedisClient(ctx context.Context, conn GoRedisClientConn) *GoRedis { // JSONSet used to set a json object // // ReJSON syntax: -// JSON.SET -// [NX | XX] // +// JSON.SET +// [NX | XX] func (r *GoRedis) JSONSet(key string, path string, obj interface{}, opts ...rjs.SetOption) (res interface{}, err error) { // nolint: lll if len(opts) > 1 { @@ -68,15 +69,14 @@ func (r *GoRedis) JSONSet(key string, path string, obj interface{}, opts ...rjs. // JSONGet used to get a json object // // ReJSON syntax: -// JSON.GET +// +// JSON.GET // [INDENT indentation-string] // [NEWLINE line-break-string] // [SPACE space-string] // [NOESCAPE] // [path ...] -// func (r *GoRedis) JSONGet(key, path string, opts ...rjs.GetOption) (res interface{}, err error) { - if len(opts) > 4 { return nil, rjs.ErrTooManyOptionals } @@ -103,10 +103,9 @@ func (r *GoRedis) JSONGet(key, path string, opts ...rjs.GetOption) (res interfac // JSONMGet used to get path values from multiple keys // // ReJSON syntax: -// JSON.MGET [key ...] // +// JSON.MGET [key ...] func (r *GoRedis) JSONMGet(path string, keys ...string) (res interface{}, err error) { - if len(keys) == 0 { return nil, rjs.ErrNeedAtLeastOneArg } @@ -140,10 +139,9 @@ func (r *GoRedis) JSONMGet(path string, keys ...string) (res interface{}, err er // JSONDel to delete a json object // // ReJSON syntax: -// JSON.DEL // +// JSON.DEL func (r *GoRedis) JSONDel(key string, path string) (res interface{}, err error) { - name, args, err := rjs.CommandBuilder(rjs.ReJSONCommandDEL, key, path) if err != nil { return nil, err @@ -155,10 +153,9 @@ func (r *GoRedis) JSONDel(key string, path string) (res interface{}, err error) // JSONType to get the type of key or member at path. // // ReJSON syntax: -// JSON.TYPE [path] // +// JSON.TYPE [path] func (r *GoRedis) JSONType(key, path string) (res interface{}, err error) { - name, args, err := rjs.CommandBuilder(rjs.ReJSONCommandTYPE, key, path) if err != nil { return nil, err @@ -175,10 +172,9 @@ func (r *GoRedis) JSONType(key, path string) (res interface{}, err error) { // JSONNumIncrBy to increment a number by provided amount // // ReJSON syntax: -// JSON.NUMINCRBY // +// JSON.NUMINCRBY func (r *GoRedis) JSONNumIncrBy(key, path string, number int) (res interface{}, err error) { - name, args, err := rjs.CommandBuilder(rjs.ReJSONCommandNUMINCRBY, key, path, number) if err != nil { return nil, err @@ -194,10 +190,9 @@ func (r *GoRedis) JSONNumIncrBy(key, path string, number int) (res interface{}, // JSONNumMultBy to increment a number by provided amount // // ReJSON syntax: -// JSON.NUMMULTBY // +// JSON.NUMMULTBY func (r *GoRedis) JSONNumMultBy(key, path string, number int) (res interface{}, err error) { - name, args, err := rjs.CommandBuilder(rjs.ReJSONCommandNUMMULTBY, key, path, number) if err != nil { return nil, err @@ -213,10 +208,9 @@ func (r *GoRedis) JSONNumMultBy(key, path string, number int) (res interface{}, // JSONStrAppend to append a jsonstring to an existing member // // ReJSON syntax: -// JSON.STRAPPEND [path] // +// JSON.STRAPPEND [path] func (r *GoRedis) JSONStrAppend(key, path, jsonstring string) (res interface{}, err error) { - name, args, err := rjs.CommandBuilder(rjs.ReJSONCommandSTRAPPEND, key, path, jsonstring) if err != nil { return nil, err @@ -228,10 +222,9 @@ func (r *GoRedis) JSONStrAppend(key, path, jsonstring string) (res interface{}, // JSONStrLen to return the length of a string member // // ReJSON syntax: -// JSON.STRLEN [path] // +// JSON.STRLEN [path] func (r *GoRedis) JSONStrLen(key, path string) (res interface{}, err error) { - name, args, err := rjs.CommandBuilder(rjs.ReJSONCommandSTRLEN, key, path) if err != nil { return nil, err @@ -243,10 +236,9 @@ func (r *GoRedis) JSONStrLen(key, path string) (res interface{}, err error) { // JSONArrAppend to append json value into array at path // // ReJSON syntax: -// JSON.ARRAPPEND [json ...] // +// JSON.ARRAPPEND [json ...] func (r *GoRedis) JSONArrAppend(key, path string, values ...interface{}) (res interface{}, err error) { - if len(values) == 0 { return nil, rjs.ErrNeedAtLeastOneArg } @@ -265,10 +257,9 @@ func (r *GoRedis) JSONArrAppend(key, path string, values ...interface{}) (res in // JSONArrLen returns the length of the json array at path // // ReJSON syntax: -// JSON.ARRLEN [path] // +// JSON.ARRLEN [path] func (r *GoRedis) JSONArrLen(key, path string) (res interface{}, err error) { - name, args, err := rjs.CommandBuilder(rjs.ReJSONCommandARRLEN, key, path) if err != nil { return nil, err @@ -281,10 +272,9 @@ func (r *GoRedis) JSONArrLen(key, path string) (res interface{}, err error) { // to pop last element use rejson.PopArrLast // // ReJSON syntax: -// JSON.ARRPOP [path [index]] // +// JSON.ARRPOP [path [index]] func (r *GoRedis) JSONArrPop(key, path string, index int) (res interface{}, err error) { - name, args, err := rjs.CommandBuilder(rjs.ReJSONCommandARRPOP, key, path, index) if err != nil { return nil, err @@ -301,8 +291,8 @@ func (r *GoRedis) JSONArrPop(key, path string, index int) (res interface{}, err // JSONArrIndex returns the index of the json element provided and return -1 if element is not present // // ReJSON syntax: -// JSON.ARRINDEX [start [stop]] // +// JSON.ARRINDEX [start [stop]] func (r *GoRedis) JSONArrIndex(key, path string, jsonValue interface{}, optionalRange ...int) (res interface{}, err error) { // nolint: lll args := []interface{}{key, path, jsonValue} @@ -327,10 +317,9 @@ func (r *GoRedis) JSONArrIndex(key, path string, jsonValue interface{}, optional // JSONArrTrim trims an array so that it contains only the specified inclusive range of elements // // ReJSON syntax: -// JSON.ARRTRIM // +// JSON.ARRTRIM func (r *GoRedis) JSONArrTrim(key, path string, start, end int) (res interface{}, err error) { - name, args, err := rjs.CommandBuilder(rjs.ReJSONCommandARRTRIM, key, path, start, end) if err != nil { return nil, err @@ -342,10 +331,9 @@ func (r *GoRedis) JSONArrTrim(key, path string, start, end int) (res interface{} // JSONArrInsert inserts the json value(s) into the array at path before the index (shifts to the right). // // ReJSON syntax: -// JSON.ARRINSERT [json ...] // +// JSON.ARRINSERT [json ...] func (r *GoRedis) JSONArrInsert(key, path string, index int, values ...interface{}) (res interface{}, err error) { - if len(values) == 0 { return nil, rjs.ErrNeedAtLeastOneArg } @@ -364,10 +352,9 @@ func (r *GoRedis) JSONArrInsert(key, path string, index int, values ...interface // JSONObjKeys returns the keys in the object that's referenced by path // // ReJSON syntax: -// JSON.OBJKEYS [path] // +// JSON.OBJKEYS [path] func (r *GoRedis) JSONObjKeys(key, path string) (res interface{}, err error) { - name, args, err := rjs.CommandBuilder(rjs.ReJSONCommandOBJKEYS, key, path) if err != nil { return nil, err @@ -389,10 +376,9 @@ func (r *GoRedis) JSONObjKeys(key, path string) (res interface{}, err error) { // JSONObjLen report the number of keys in the JSON Object at path in key // // ReJSON syntax: -// JSON.OBJLEN [path] // +// JSON.OBJLEN [path] func (r *GoRedis) JSONObjLen(key, path string) (res interface{}, err error) { - name, args, err := rjs.CommandBuilder(rjs.ReJSONCommandOBJLEN, key, path) if err != nil { return nil, err @@ -404,12 +390,11 @@ func (r *GoRedis) JSONObjLen(key, path string) (res interface{}, err error) { // JSONDebug reports information // // ReJSON syntax: -// JSON.DEBUG +// +// JSON.DEBUG // JSON.DEBUG MEMORY [path] - report the memory usage in bytes of a value. path defaults to root if not provided. // JSON.DEBUG HELP - reply with a helpful message -// func (r *GoRedis) JSONDebug(subcommand rjs.DebugSubCommand, key, path string) (res interface{}, err error) { - if subcommand != rjs.DebugMemorySubcommand && subcommand != rjs.DebugHelpSubcommand { err = fmt.Errorf("unknown subcommand - try `JSON.DEBUG HELP`") return @@ -439,10 +424,9 @@ func (r *GoRedis) JSONDebug(subcommand rjs.DebugSubCommand, key, path string) (r // JSONForget is an alias for JSONDel // // ReJSON syntax: -// JSON.FORGET [path] // +// JSON.FORGET [path] func (r *GoRedis) JSONForget(key, path string) (res interface{}, err error) { - name, args, err := rjs.CommandBuilder(rjs.ReJSONCommandFORGET, key, path) if err != nil { return nil, err @@ -454,10 +438,9 @@ func (r *GoRedis) JSONForget(key, path string) (res interface{}, err error) { // JSONResp returns the JSON in key in Redis Serialization Protocol (RESP). // // ReJSON syntax: -// JSON.RESP [path] // +// JSON.RESP [path] func (r *GoRedis) JSONResp(key, path string) (res interface{}, err error) { - name, args, err := rjs.CommandBuilder(rjs.ReJSONCommandRESP, key, path) if err != nil { return nil, err diff --git a/clients/redigo.go b/clients/redigo.go index 2c3c707..475a790 100644 --- a/clients/redigo.go +++ b/clients/redigo.go @@ -2,8 +2,9 @@ package clients import ( "fmt" - "github.com/nitishm/go-rejson/v4/rjs" "strings" + + "github.com/nitishm/go-rejson/v4/rjs" ) // RedigoClientConn - an abstracted interface for redigo.Conn and redigo.ConnWithTimeout @@ -20,11 +21,10 @@ type Redigo struct { // JSONSet used to set a json object // // ReJSON syntax: -// JSON.SET -// [NX | XX] // +// JSON.SET +// [NX | XX] func (r *Redigo) JSONSet(key string, path string, obj interface{}, opts ...rjs.SetOption) (res interface{}, err error) { - if len(opts) > 1 { return nil, rjs.ErrTooManyOptionals } @@ -44,15 +44,14 @@ func (r *Redigo) JSONSet(key string, path string, obj interface{}, opts ...rjs.S // JSONGet used to get a json object // // ReJSON syntax: -// JSON.GET +// +// JSON.GET // [INDENT indentation-string] // [NEWLINE line-break-string] // [SPACE space-string] // [NOESCAPE] // [path ...] -// func (r *Redigo) JSONGet(key, path string, opts ...rjs.GetOption) (res interface{}, err error) { - if len(opts) > 4 { return nil, rjs.ErrTooManyOptionals } @@ -74,10 +73,9 @@ func (r *Redigo) JSONGet(key, path string, opts ...rjs.GetOption) (res interface // JSONMGet used to get path values from multiple keys // // ReJSON syntax: -// JSON.MGET [key ...] // +// JSON.MGET [key ...] func (r *Redigo) JSONMGet(path string, keys ...string) (res interface{}, err error) { - if len(keys) == 0 { return nil, rjs.ErrNeedAtLeastOneArg } @@ -97,10 +95,9 @@ func (r *Redigo) JSONMGet(path string, keys ...string) (res interface{}, err err // JSONDel used to delete a json object // // ReJSON syntax: -// JSON.DEL // +// JSON.DEL func (r *Redigo) JSONDel(key string, path string) (res interface{}, err error) { - name, args, err := rjs.CommandBuilder(rjs.ReJSONCommandDEL, key, path) if err != nil { return nil, err @@ -111,10 +108,9 @@ func (r *Redigo) JSONDel(key string, path string) (res interface{}, err error) { // JSONType used to get the type of key or member at path. // // ReJSON syntax: -// JSON.TYPE [path] // +// JSON.TYPE [path] func (r *Redigo) JSONType(key, path string) (res interface{}, err error) { - name, args, err := rjs.CommandBuilder(rjs.ReJSONCommandTYPE, key, path) if err != nil { return nil, err @@ -141,10 +137,9 @@ func (r *Redigo) JSONType(key, path string) (res interface{}, err error) { // JSONNumIncrBy used to increment a number by provided amount // // ReJSON syntax: -// JSON.NUMINCRBY // +// JSON.NUMINCRBY func (r *Redigo) JSONNumIncrBy(key, path string, number int) (res interface{}, err error) { - name, args, err := rjs.CommandBuilder(rjs.ReJSONCommandNUMINCRBY, key, path, number) if err != nil { return nil, err @@ -155,10 +150,9 @@ func (r *Redigo) JSONNumIncrBy(key, path string, number int) (res interface{}, e // JSONNumMultBy to multiply a number by provided amount // // ReJSON syntax: -// JSON.NUMMULTBY // +// JSON.NUMMULTBY func (r *Redigo) JSONNumMultBy(key, path string, number int) (res interface{}, err error) { - name, args, err := rjs.CommandBuilder(rjs.ReJSONCommandNUMMULTBY, key, path, number) if err != nil { return nil, err @@ -169,10 +163,9 @@ func (r *Redigo) JSONNumMultBy(key, path string, number int) (res interface{}, e // JSONStrAppend used to append a jsonstring to an existing member // // ReJSON syntax: -// JSON.STRAPPEND [path] // +// JSON.STRAPPEND [path] func (r *Redigo) JSONStrAppend(key, path, jsonstring string) (res interface{}, err error) { - name, args, err := rjs.CommandBuilder(rjs.ReJSONCommandSTRAPPEND, key, path, jsonstring) if err != nil { return nil, err @@ -183,10 +176,9 @@ func (r *Redigo) JSONStrAppend(key, path, jsonstring string) (res interface{}, e // JSONStrLen used to return the length of a string member // // ReJSON syntax: -// JSON.STRLEN [path] // +// JSON.STRLEN [path] func (r *Redigo) JSONStrLen(key, path string) (res interface{}, err error) { - name, args, err := rjs.CommandBuilder(rjs.ReJSONCommandSTRLEN, key, path) if err != nil { return nil, err @@ -197,10 +189,9 @@ func (r *Redigo) JSONStrLen(key, path string) (res interface{}, err error) { // JSONArrAppend used to append json value into array at path // // ReJSON syntax: -// JSON.ARRAPPEND [json ...] // +// JSON.ARRAPPEND [json ...] func (r *Redigo) JSONArrAppend(key, path string, values ...interface{}) (res interface{}, err error) { - if len(values) == 0 { return nil, rjs.ErrNeedAtLeastOneArg } @@ -218,10 +209,9 @@ func (r *Redigo) JSONArrAppend(key, path string, values ...interface{}) (res int // JSONArrLen returns the length of the json array at path // // ReJSON syntax: -// JSON.ARRLEN [path] // +// JSON.ARRLEN [path] func (r *Redigo) JSONArrLen(key, path string) (res interface{}, err error) { - name, args, err := rjs.CommandBuilder(rjs.ReJSONCommandARRLEN, key, path) if err != nil { return nil, err @@ -233,10 +223,9 @@ func (r *Redigo) JSONArrLen(key, path string) (res interface{}, err error) { // to pop last element use rejson.PopArrLast // // ReJSON syntax: -// JSON.ARRPOP [path [index]] // +// JSON.ARRPOP [path [index]] func (r *Redigo) JSONArrPop(key, path string, index int) (res interface{}, err error) { - name, args, err := rjs.CommandBuilder(rjs.ReJSONCommandARRPOP, key, path, index) if err != nil { return nil, err @@ -247,8 +236,8 @@ func (r *Redigo) JSONArrPop(key, path string, index int) (res interface{}, err e // JSONArrIndex returns the index of the json element provided and return -1 if element is not present // // ReJSON syntax: -// JSON.ARRINDEX [start [stop]] // +// JSON.ARRINDEX [start [stop]] func (r *Redigo) JSONArrIndex(key, path string, jsonValue interface{}, optionalRange ...int) (res interface{}, err error) { // nolint: lll args := []interface{}{key, path, jsonValue} @@ -272,10 +261,9 @@ func (r *Redigo) JSONArrIndex(key, path string, jsonValue interface{}, optionalR // JSONArrTrim trims an array so that it contains only the specified inclusive range of elements // // ReJSON syntax: -// JSON.ARRTRIM // +// JSON.ARRTRIM func (r *Redigo) JSONArrTrim(key, path string, start, end int) (res interface{}, err error) { - name, args, err := rjs.CommandBuilder(rjs.ReJSONCommandARRTRIM, key, path, start, end) if err != nil { return nil, err @@ -286,10 +274,9 @@ func (r *Redigo) JSONArrTrim(key, path string, start, end int) (res interface{}, // JSONArrInsert inserts the json value(s) into the array at path before the index (shifts to the right). // // ReJSON syntax: -// JSON.ARRINSERT [json ...] // +// JSON.ARRINSERT [json ...] func (r *Redigo) JSONArrInsert(key, path string, index int, values ...interface{}) (res interface{}, err error) { - if len(values) == 0 { return nil, rjs.ErrNeedAtLeastOneArg } @@ -307,10 +294,9 @@ func (r *Redigo) JSONArrInsert(key, path string, index int, values ...interface{ // JSONObjKeys returns the keys in the object that's referenced by path // // ReJSON syntax: -// JSON.OBJKEYS [path] // +// JSON.OBJKEYS [path] func (r *Redigo) JSONObjKeys(key, path string) (res interface{}, err error) { - name, args, err := rjs.CommandBuilder(rjs.ReJSONCommandOBJKEYS, key, path) if err != nil { return nil, err @@ -331,10 +317,9 @@ func (r *Redigo) JSONObjKeys(key, path string) (res interface{}, err error) { // JSONObjLen report the number of keys in the JSON Object at path in key // // ReJSON syntax: -// JSON.OBJLEN [path] // +// JSON.OBJLEN [path] func (r *Redigo) JSONObjLen(key, path string) (res interface{}, err error) { - name, args, err := rjs.CommandBuilder(rjs.ReJSONCommandOBJLEN, key, path) if err != nil { return nil, err @@ -345,12 +330,11 @@ func (r *Redigo) JSONObjLen(key, path string) (res interface{}, err error) { // JSONDebug reports information // // ReJSON syntax: -// JSON.DEBUG +// +// JSON.DEBUG // JSON.DEBUG MEMORY [path] - report the memory usage in bytes of a value. path defaults to root if not provided. // JSON.DEBUG HELP - reply with a helpful message -// func (r *Redigo) JSONDebug(subcommand rjs.DebugSubCommand, key, path string) (res interface{}, err error) { - if subcommand != rjs.DebugMemorySubcommand && subcommand != rjs.DebugHelpSubcommand { err = fmt.Errorf("unknown subcommand - try `JSON.DEBUG HELP`") return @@ -379,10 +363,9 @@ func (r *Redigo) JSONDebug(subcommand rjs.DebugSubCommand, key, path string) (re // JSONForget is an alias for JSONDel // // ReJSON syntax: -// JSON.FORGET [path] // +// JSON.FORGET [path] func (r *Redigo) JSONForget(key, path string) (res interface{}, err error) { - name, args, err := rjs.CommandBuilder(rjs.ReJSONCommandFORGET, key, path) if err != nil { return nil, err @@ -393,10 +376,9 @@ func (r *Redigo) JSONForget(key, path string) (res interface{}, err error) { // JSONResp returns the JSON in key in Redis Serialization Protocol (RESP). // // ReJSON syntax: -// JSON.RESP [path] // +// JSON.RESP [path] func (r *Redigo) JSONResp(key, path string) (res interface{}, err error) { - name, args, err := rjs.CommandBuilder(rjs.ReJSONCommandRESP, key, path) if err != nil { return nil, err diff --git a/doc.go b/doc.go index a34a6c8..c286520 100644 --- a/doc.go +++ b/doc.go @@ -21,31 +21,30 @@ Redis-api client GoModule/Redigo (https://github.com/gomodule/redigo/redis). Go-ReJSON supports both the clients. Use any of the above two client you want, Go-ReJSON helps you out with all its features and functionalities in a more generic and standard way. - -Installation - +# Installation To install and use ReJSON module, one must have the pre-requisites installed and setup. Run the script in : ./install-redis-rejson.sh - -Examples - +# Examples Create New ReJSON Handler + rh := rejson.NewReJSONHandler() Set Redigo Client and use ReJSON in it + conn, _ := redis.Dial("tcp", *addr) rh.SetRedigoClient(conn) Similarly, one can set client for Go-Redis + cli := goredis.NewClient(&goredis.Options{Addr: *addr}) rh.SetGoRedisClient(cli) And now, one can directly use ReJSON commands using the handler - res, err := rh.JSONSet("str", ".", "string") + res, err := rh.JSONSet("str", ".", "string") */ package rejson diff --git a/examples/json_array/json_array.go b/examples/json_array/json_array.go index b855361..7f17e96 100644 --- a/examples/json_array/json_array.go +++ b/examples/json_array/json_array.go @@ -9,8 +9,9 @@ import ( "github.com/nitishm/go-rejson/v4/rjs" - goredis "github.com/go-redis/redis/v8" "github.com/gomodule/redigo/redis" + goredis "github.com/redis/go-redis/v9" + "github.com/nitishm/go-rejson/v4" ) @@ -169,7 +170,7 @@ func main() { log.Fatalf("goredis - failed to communicate to redis-server: %v", err) } }() - rh.SetGoRedisClient(cli) + rh.SetGoRedisClientWithContext(context.Background(), cli) fmt.Println("\nExecuting Example_JSONSET for Redigo Client") Example_JSONArray(rh) } diff --git a/examples/json_obj/json_obj.go b/examples/json_obj/json_obj.go index 3c86b3a..3b48993 100644 --- a/examples/json_obj/json_obj.go +++ b/examples/json_obj/json_obj.go @@ -10,8 +10,8 @@ import ( "github.com/nitishm/go-rejson/v4" "github.com/nitishm/go-rejson/v4/rjs" - goredis "github.com/go-redis/redis/v8" "github.com/gomodule/redigo/redis" + goredis "github.com/redis/go-redis/v9" ) var ctx = context.Background() @@ -119,7 +119,7 @@ func main() { log.Fatalf("goredis - failed to communicate to redis-server: %v", err) } }() - rh.SetGoRedisClient(cli) + rh.SetGoRedisClientWithContext(context.Background(), cli) fmt.Println("\nExecuting Example_JSONSET for Redigo Client") Example_JSONObj(rh) } diff --git a/examples/json_set/json_set.go b/examples/json_set/json_set.go index 95e2d23..2ede6d7 100644 --- a/examples/json_set/json_set.go +++ b/examples/json_set/json_set.go @@ -7,8 +7,9 @@ import ( "fmt" "log" - goredis "github.com/go-redis/redis/v8" "github.com/gomodule/redigo/redis" + goredis "github.com/redis/go-redis/v9" + "github.com/nitishm/go-rejson/v4" ) @@ -97,7 +98,7 @@ func main() { log.Fatalf("goredis - failed to communicate to redis-server: %v", err) } }() - rh.SetGoRedisClient(cli) + rh.SetGoRedisClientWithContext(context.Background(), cli) fmt.Println("\nExecuting Example_JSONSET for Redigo Client") Example_JSONSet(rh) } diff --git a/go.mod b/go.mod index 93d8dff..0fbdf4d 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,6 @@ module github.com/nitishm/go-rejson/v4 go 1.14 require ( - github.com/go-redis/redis/v8 v8.4.4 github.com/gomodule/redigo v1.8.3 + github.com/redis/go-redis/v9 v9.0.2 ) diff --git a/go.sum b/go.sum index 47660c5..67a5df1 100644 --- a/go.sum +++ b/go.sum @@ -1,99 +1,31 @@ -github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= -github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/bsm/ginkgo/v2 v2.5.0 h1:aOAnND1T40wEdAtkGSkvSICWeQ8L3UASX7YVCqQx+eQ= +github.com/bsm/ginkgo/v2 v2.5.0/go.mod h1:AiKlXPm7ItEHNc/2+OkrNG4E0ITzojb9/xWzvQ9XZ9w= +github.com/bsm/gomega v1.20.0 h1:JhAwLmtRzXFTx2AkALSLa8ijZafntmhSoU63Ok18Uq8= +github.com/bsm/gomega v1.20.0/go.mod h1:JifAceMQ4crZIWYUKrlGcmbN3bqHogVTADMD2ATsbwk= +github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= +github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= -github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= -github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= -github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/go-redis/redis/v8 v8.4.4 h1:fGqgxCTR1sydaKI00oQf3OmkU/DIe/I/fYXvGklCIuc= -github.com/go-redis/redis/v8 v8.4.4/go.mod h1:nA0bQuF0i5JFx4Ta9RZxGKXFrQ8cRWntra97f0196iY= -github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= -github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/gomodule/redigo v1.8.3 h1:HR0kYDX2RJZvAup8CsiJwxB4dTCSC0AaUq6S4SiLwUc= github.com/gomodule/redigo v1.8.3/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M= -github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= -github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78= -github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= -github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/ginkgo v1.14.2 h1:8mVmC9kjFFmA8H4pKMUhcblgifdkOIXPvbhN1T36q1M= -github.com/onsi/ginkgo v1.14.2/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= -github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= -github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.10.4 h1:NiTx7EEvBzu9sFOD1zORteLSt3o8gnlvZZwSE9TnY9U= -github.com/onsi/gomega v1.10.4/go.mod h1:g/HbgYopi++010VEqkFgJHKC09uJiW9UkXvMUuKHUCQ= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/redis/go-redis/v9 v9.0.2 h1:BA426Zqe/7r56kCcvxYLWe1mkaz71LKF77GwgFzSxfE= +github.com/redis/go-redis/v9 v9.0.2/go.mod h1:/xDTe9EF1LM61hek62Poq2nzQSGj0xSrEtEHbBQevps= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -go.opentelemetry.io/otel v0.15.0 h1:CZFy2lPhxd4HlhZnYK8gRyDotksO3Ip9rBweY1vVYJw= -go.opentelemetry.io/otel v0.15.0/go.mod h1:e4GKElweB8W2gWUqbghw0B8t5MCTccc9212eNHnOHwA= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb h1:eBmm0M9fYhWpKZLjQUUKka/LtIxf46G4fxeEz5KJr9U= -golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= -gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= -gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/rejson.go b/rejson.go index b45710e..e915f33 100644 --- a/rejson.go +++ b/rejson.go @@ -59,12 +59,12 @@ type ReJSON interface { // JSONSet used to set a json object // // ReJSON syntax: -// JSON.SET -// [NX | XX] // +// JSON.SET +// [NX | XX] func (r *Handler) JSONSet(key string, path string, obj interface{}, opts ...rjs.SetOption) ( - res interface{}, err error) { - + res interface{}, err error, +) { if r.clientName == rjs.ClientInactive { return nil, rjs.ErrNoClientSet } @@ -74,13 +74,13 @@ func (r *Handler) JSONSet(key string, path string, obj interface{}, opts ...rjs. // JSONGet used to get a json object // // ReJSON syntax: -// JSON.GET +// +// JSON.GET // [INDENT indentation-string] // [NEWLINE line-break-string] // [SPACE space-string] // [NOESCAPE] // [path ...] -// func (r *Handler) JSONGet(key, path string, opts ...rjs.GetOption) (res interface{}, err error) { if r.clientName == rjs.ClientInactive { return nil, rjs.ErrNoClientSet @@ -91,8 +91,8 @@ func (r *Handler) JSONGet(key, path string, opts ...rjs.GetOption) (res interfac // JSONMGet used to get path values from multiple keys // // ReJSON syntax: -// JSON.MGET [key ...] // +// JSON.MGET [key ...] func (r *Handler) JSONMGet(path string, keys ...string) (res interface{}, err error) { if r.clientName == rjs.ClientInactive { return nil, rjs.ErrNoClientSet @@ -103,8 +103,8 @@ func (r *Handler) JSONMGet(path string, keys ...string) (res interface{}, err er // JSONDel to delete a json object // // ReJSON syntax: -// JSON.DEL // +// JSON.DEL func (r *Handler) JSONDel(key string, path string) (res interface{}, err error) { if r.clientName == rjs.ClientInactive { return nil, rjs.ErrNoClientSet @@ -115,8 +115,8 @@ func (r *Handler) JSONDel(key string, path string) (res interface{}, err error) // JSONType to get the type of key or member at path. // // ReJSON syntax: -// JSON.TYPE [path] // +// JSON.TYPE [path] func (r *Handler) JSONType(key, path string) (res interface{}, err error) { if r.clientName == rjs.ClientInactive { return nil, rjs.ErrNoClientSet @@ -127,8 +127,8 @@ func (r *Handler) JSONType(key, path string) (res interface{}, err error) { // JSONNumIncrBy to increment a number by provided amount // // ReJSON syntax: -// JSON.NUMINCRBY // +// JSON.NUMINCRBY func (r *Handler) JSONNumIncrBy(key, path string, number int) (res interface{}, err error) { if r.clientName == rjs.ClientInactive { return nil, rjs.ErrNoClientSet @@ -139,8 +139,8 @@ func (r *Handler) JSONNumIncrBy(key, path string, number int) (res interface{}, // JSONNumMultBy to increment a number by provided amount // // ReJSON syntax: -// JSON.NUMMULTBY // +// JSON.NUMMULTBY func (r *Handler) JSONNumMultBy(key, path string, number int) (res interface{}, err error) { if r.clientName == rjs.ClientInactive { return nil, rjs.ErrNoClientSet @@ -151,8 +151,8 @@ func (r *Handler) JSONNumMultBy(key, path string, number int) (res interface{}, // JSONStrAppend to append a jsonstring to an existing member // // ReJSON syntax: -// JSON.STRAPPEND [path] // +// JSON.STRAPPEND [path] func (r *Handler) JSONStrAppend(key, path, jsonstring string) (res interface{}, err error) { if r.clientName == rjs.ClientInactive { return nil, rjs.ErrNoClientSet @@ -163,8 +163,8 @@ func (r *Handler) JSONStrAppend(key, path, jsonstring string) (res interface{}, // JSONStrLen to return the length of a string member // // ReJSON syntax: -// JSON.STRLEN [path] // +// JSON.STRLEN [path] func (r *Handler) JSONStrLen(key, path string) (res interface{}, err error) { if r.clientName == rjs.ClientInactive { return nil, rjs.ErrNoClientSet @@ -175,8 +175,8 @@ func (r *Handler) JSONStrLen(key, path string) (res interface{}, err error) { // JSONArrAppend to append json value into array at path // // ReJSON syntax: -// JSON.ARRAPPEND [json ...] // +// JSON.ARRAPPEND [json ...] func (r *Handler) JSONArrAppend(key, path string, values ...interface{}) (res interface{}, err error) { if r.clientName == rjs.ClientInactive { return nil, rjs.ErrNoClientSet @@ -187,8 +187,8 @@ func (r *Handler) JSONArrAppend(key, path string, values ...interface{}) (res in // JSONArrLen returns the length of the json array at path // // ReJSON syntax: -// JSON.ARRLEN [path] // +// JSON.ARRLEN [path] func (r *Handler) JSONArrLen(key, path string) (res interface{}, err error) { if r.clientName == rjs.ClientInactive { return nil, rjs.ErrNoClientSet @@ -200,8 +200,8 @@ func (r *Handler) JSONArrLen(key, path string) (res interface{}, err error) { // to pop last element use rejson.PopArrLast // // ReJSON syntax: -// JSON.ARRPOP [path [index]] // +// JSON.ARRPOP [path [index]] func (r *Handler) JSONArrPop(key, path string, index int) (res interface{}, err error) { if r.clientName == rjs.ClientInactive { return nil, rjs.ErrNoClientSet @@ -212,11 +212,11 @@ func (r *Handler) JSONArrPop(key, path string, index int) (res interface{}, err // JSONArrIndex returns the index of the json element provided and return -1 if element is not present // // ReJSON syntax: -// JSON.ARRINDEX [start [stop]] // +// JSON.ARRINDEX [start [stop]] func (r *Handler) JSONArrIndex(key, path string, jsonValue interface{}, optionalRange ...int) ( - res interface{}, err error) { - + res interface{}, err error, +) { if r.clientName == rjs.ClientInactive { return nil, rjs.ErrNoClientSet } @@ -226,8 +226,8 @@ func (r *Handler) JSONArrIndex(key, path string, jsonValue interface{}, optional // JSONArrTrim trims an array so that it contains only the specified inclusive range of elements // // ReJSON syntax: -// JSON.ARRTRIM // +// JSON.ARRTRIM func (r *Handler) JSONArrTrim(key, path string, start, end int) (res interface{}, err error) { if r.clientName == rjs.ClientInactive { return nil, rjs.ErrNoClientSet @@ -238,8 +238,8 @@ func (r *Handler) JSONArrTrim(key, path string, start, end int) (res interface{} // JSONArrInsert inserts the json value(s) into the array at path before the index (shifts to the right). // // ReJSON syntax: -// JSON.ARRINSERT [json ...] // +// JSON.ARRINSERT [json ...] func (r *Handler) JSONArrInsert(key, path string, index int, values ...interface{}) (res interface{}, err error) { if r.clientName == rjs.ClientInactive { return nil, rjs.ErrNoClientSet @@ -250,8 +250,8 @@ func (r *Handler) JSONArrInsert(key, path string, index int, values ...interface // JSONObjKeys returns the keys in the object that's referenced by path // // ReJSON syntax: -// JSON.OBJKEYS [path] // +// JSON.OBJKEYS [path] func (r *Handler) JSONObjKeys(key, path string) (res interface{}, err error) { if r.clientName == rjs.ClientInactive { return nil, rjs.ErrNoClientSet @@ -262,8 +262,8 @@ func (r *Handler) JSONObjKeys(key, path string) (res interface{}, err error) { // JSONObjLen report the number of keys in the JSON Object at path in key // // ReJSON syntax: -// JSON.OBJLEN [path] // +// JSON.OBJLEN [path] func (r *Handler) JSONObjLen(key, path string) (res interface{}, err error) { if r.clientName == rjs.ClientInactive { return nil, rjs.ErrNoClientSet @@ -274,10 +274,10 @@ func (r *Handler) JSONObjLen(key, path string) (res interface{}, err error) { // JSONDebug reports information // // ReJSON syntax: -// JSON.DEBUG +// +// JSON.DEBUG // JSON.DEBUG MEMORY [path] - report the memory usage in bytes of a value. path defaults to root if not provided. // JSON.DEBUG HELP - reply with a helpful message -// func (r *Handler) JSONDebug(subCmd rjs.DebugSubCommand, key, path string) (res interface{}, err error) { if r.clientName == rjs.ClientInactive { return nil, rjs.ErrNoClientSet @@ -288,8 +288,8 @@ func (r *Handler) JSONDebug(subCmd rjs.DebugSubCommand, key, path string) (res i // JSONForget is an alias for JSONDel // // ReJSON syntax: -// JSON.FORGET [path] // +// JSON.FORGET [path] func (r *Handler) JSONForget(key, path string) (res interface{}, err error) { if r.clientName == rjs.ClientInactive { return nil, rjs.ErrNoClientSet @@ -300,8 +300,8 @@ func (r *Handler) JSONForget(key, path string) (res interface{}, err error) { // JSONResp returns the JSON in key in Redis Serialization Protocol (RESP). // // ReJSON syntax: -// JSON.RESP [path] // +// JSON.RESP [path] func (r *Handler) JSONResp(key, path string) (res interface{}, err error) { if r.clientName == rjs.ClientInactive { return nil, rjs.ErrNoClientSet diff --git a/rejson_test.go b/rejson_test.go index 3aeebb1..9ebd4aa 100644 --- a/rejson_test.go +++ b/rejson_test.go @@ -9,8 +9,8 @@ import ( "github.com/nitishm/go-rejson/v4/rjs" - goredis "github.com/go-redis/redis/v8" redigo "github.com/gomodule/redigo/redis" + goredis "github.com/redis/go-redis/v9" ) func TestUnsupportedCommand(t *testing.T) { diff --git a/rjs/commands.go b/rjs/commands.go index f8332a9..6a4d3bd 100644 --- a/rjs/commands.go +++ b/rjs/commands.go @@ -170,8 +170,8 @@ func commandJSONDebug(argsIn ...interface{}) (argsOut []interface{}, err error) // This is especially useful if you do not need to client's `Do()` method // and instead need to use the JSON.* commands in the MUTLI/EXEC scenario // along with some other operations like -// GET/SET/HGET/HSET/... // +// GET/SET/HGET/HSET/... func CommandBuilder(commandNameIn ReJSONCommandID, argsIn ...interface{}) (commandNameOut string, argsOut []interface{}, err error) { // nolint: lll cmd, commandNameOut, err := commandNameIn.Details() diff --git a/rjs/options.go b/rjs/options.go index c6c7526..2e98fa7 100644 --- a/rjs/options.go +++ b/rjs/options.go @@ -4,7 +4,8 @@ package rjs // It also abstracts options from the required parameters of the commands // // Like: -// JSON.GET, JSON.SET, JSON.ARRINDEX, JSON.ARRPOP +// +// JSON.GET, JSON.SET, JSON.ARRINDEX, JSON.ARRPOP type ReJSONOption interface { // Value returns the value of the option being used Value() []interface{} @@ -16,10 +17,10 @@ type ReJSONOption interface { // GetOption implements ReJSONOption for JSON.GET Method // Get Options: -// * INDENT (with default set to a tab, '\t') -// * NEWLINE (with default set to a new line, '\n') -// * SPACE (with default set to a space, ' ') -// * NOESCAPE (a boolean type option) +// - INDENT (with default set to a tab, '\t') +// - NEWLINE (with default set to a new line, '\n') +// - SPACE (with default set to a space, ' ') +// - NOESCAPE (a boolean type option) type GetOption struct { name string Arg string @@ -45,7 +46,7 @@ func (g *GetOption) SetValue(arg string) { // SetOption implements ReJSONOption for JSON.SET Method // Set Options: -// * NX or XX +// - NX or XX type SetOption string // MethodID returns the name of the method i.e. JSON.SET diff --git a/set_client.go b/set_client.go index 58f1fcd..8bfbf6b 100644 --- a/set_client.go +++ b/set_client.go @@ -27,7 +27,7 @@ func (r *Handler) SetRedigoClient(conn clients.RedigoClientConn) { r.implementation = &clients.Redigo{Conn: conn} } -// SetGoRedisClient sets Go-Redis (https://github.com/go-redis/redis) client to +// Deprecated: SetGoRedisClient sets Go-Redis (https://github.com/go-redis/redis) client to // the handler. It is left for backward compatibility. func (r *Handler) SetGoRedisClient(conn clients.GoRedisClientConn) { r.SetGoRedisClientWithContext(context.Background(), conn)