update
parent
746ec6be90
commit
e9756f7f54
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue