From e9756f7f5404aa47af8ac84cba5843eaf1dc552a Mon Sep 17 00:00:00 2001 From: kzkzzzz Date: Wed, 24 May 2023 22:06:29 +0800 Subject: [PATCH] update --- myredis/redis.go | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) 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