리턴타입 되돌림. 키는 하나여도 리턴은 여러개 가능

This commit is contained in:
2023-08-10 15:35:16 +09:00
parent e4ac505928
commit a57de9715c

View File

@ -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) {