main
kzkzzzz 2023-05-24 22:06:29 +08:00
parent 746ec6be90
commit e9756f7f54
1 changed files with 7 additions and 12 deletions

View File

@ -140,23 +140,18 @@ func (r *MyRedis) SetSimple(key string, value interface{}, t ...time.Duration) (
} }
// GetJson json序列化 // GetJson json序列化
func (r *MyRedis) GetJson(key string) (interface{}, error) { func (r *MyRedis) GetJson(key string, result interface{}) error {
ctx := context.Background() ctx := context.Background()
res := r.Client.Get(ctx, key) res, err := r.Client.Get(ctx, key).Bytes()
if res.Err() != nil { if err != nil {
return nil, res.Err() return err
} }
b, err := res.Bytes() err = jsoniter.Unmarshal(res, &result)
if err != nil { 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{} return nil
err = jsoniter.Unmarshal(b, &result)
if err != nil {
return nil, fmt.Errorf("get key:%s 反序列化json失败(-2)", key)
}
return result, nil
} }
// SetJson json序列化set // SetJson json序列化set