From a57de9715cb7f26f088103eb081a9ba1224e776b Mon Sep 17 00:00:00 2001 From: mountain Date: Thu, 10 Aug 2023 15:35:16 +0900 Subject: [PATCH] =?UTF-8?q?=EB=A6=AC=ED=84=B4=ED=83=80=EC=9E=85=20?= =?UTF-8?q?=EB=90=98=EB=8F=8C=EB=A6=BC.=20=ED=82=A4=EB=8A=94=20=ED=95=98?= =?UTF-8?q?=EB=82=98=EC=97=AC=EB=8F=84=20=EB=A6=AC=ED=84=B4=EC=9D=80=20?= =?UTF-8?q?=EC=97=AC=EB=9F=AC=EA=B0=9C=20=EA=B0=80=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- redis.go | 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/redis.go b/redis.go index 659027a..d3807af 100644 --- a/redis.go +++ b/redis.go @@ -191,26 +191,12 @@ func (rh *RedisonHandler) JSONGet(key, path string, opts ...RedisonGetOption) (r return rh.Do(rh.ctx, args...).Result() } -func (rh *RedisonHandler) JSONGetString(key, path string) (string, error) { - arr, err := respToArray[string](rh.JSONResp(key, path)) - if err != nil { - return "", err - } - if len(arr) > 0 { - return arr[0], nil - } - return "", nil +func (rh *RedisonHandler) JSONGetString(key, path string) ([]string, error) { + return respToArray[string](rh.JSONResp(key, path)) } -func (rh *RedisonHandler) JSONGetInt64(key, path string) (int64, error) { - arr, err := respToArray[int64](rh.JSONResp(key, path)) - if err != nil { - return 0, err - } - if len(arr) > 0 { - return arr[0], nil - } - return 0, nil +func (rh *RedisonHandler) JSONGetInt64(key, path string) ([]int64, error) { + return respToArray[int64](rh.JSONResp(key, path)) } func (rh *RedisonHandler) JSONMGet(path string, keys ...string) (res any, err error) { @@ -258,7 +244,7 @@ func (rh *RedisonHandler) JSONType(key, path string) ([]string, error) { return respToArray[string](rh.Do(rh.ctx, args...).Result()) } -func (rh *RedisonHandler) JSONNumIncrBy(key, path string, number int) (int64, error) { +func (rh *RedisonHandler) JSONNumIncrBy(key, path string, number int) ([]int64, error) { args := []any{ "JSON.NUMINCRBY", key, @@ -267,14 +253,15 @@ func (rh *RedisonHandler) JSONNumIncrBy(key, path string, number int) (int64, er } resp, err := rh.Do(rh.ctx, args...).Result() if err != nil { - return 0, err + return nil, err } - numstr := strings.Trim(resp.(string), "[]") - return strconv.ParseInt(numstr, 10, 0) + var cnts []int64 + err = json.Unmarshal([]byte(resp.(string)), &cnts) + return cnts, err } -func (rh *RedisonHandler) JSONNumMultBy(key, path string, number int) (int64, error) { +func (rh *RedisonHandler) JSONNumMultBy(key, path string, number int) (res any, err error) { args := []any{ "JSON.NUMMULTBY", key, @@ -283,11 +270,10 @@ func (rh *RedisonHandler) JSONNumMultBy(key, path string, number int) (int64, er } resp, err := rh.Do(rh.ctx, args...).Result() if err != nil { - return 0, err + return nil, err } - numstr := strings.Trim(resp.(string), "[]") - return strconv.ParseInt(numstr, 10, 0) + return resp.([]any), nil } func (rh *RedisonHandler) JSONStrAppend(key, path string, jsonstring string) ([]int64, error) {