diff --git a/myredis/redis.go b/myredis/redis.go index 126e902..372c067 100644 --- a/myredis/redis.go +++ b/myredis/redis.go @@ -140,23 +140,18 @@ func (r *MyRedis) SetSimple(key string, value interface{}, t ...time.Duration) ( } // GetJson json序列化 -func (r *MyRedis) GetJson(key string) (interface{}, error) { +func (r *MyRedis) GetJson(key string, result interface{}) error { ctx := context.Background() - res := r.Client.Get(ctx, key) - if res.Err() != nil { - return nil, res.Err() + res, err := r.Client.Get(ctx, key).Bytes() + if err != nil { + return err } - b, err := res.Bytes() + err = jsoniter.Unmarshal(res, &result) if err != nil { - return nil, fmt.Errorf("get key:%s 反序列化json失败(-1)", key) + return fmt.Errorf("get key:%s 反序列化json失败(-2)", key) } - var result interface{} - err = jsoniter.Unmarshal(b, &result) - if err != nil { - return nil, fmt.Errorf("get key:%s 反序列化json失败(-2)", key) - } - return result, nil + return nil } // SetJson json序列化set