add func get value by key with binding
This commit is contained in:
parent
2e747ff26b
commit
5d14b794dd
|
@ -3,6 +3,7 @@ package redisdb
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetValueByKey ...
|
// GetValueByKey ...
|
||||||
|
@ -15,14 +16,11 @@ func (s Server) GetValueByKey(ctx context.Context, key string) string {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetJSON ...
|
// GetValueByKeyWithBinding ...
|
||||||
func (s Server) GetJSON(ctx context.Context, key string, result interface{}) (ok bool) {
|
func (s Server) GetValueByKeyWithBinding(ctx context.Context, key string, result interface{}) error {
|
||||||
v := s.GetValueByKey(ctx, key)
|
v := s.GetValueByKey(ctx, key)
|
||||||
if v == "" {
|
if v == "" {
|
||||||
return false
|
return errors.New("key not found")
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal([]byte(v), result); err != nil {
|
return json.Unmarshal([]byte(v), result)
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue