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