add func get value by key with binding

This commit is contained in:
Nam Huynh 2022-12-05 15:16:42 +07:00
parent 2e747ff26b
commit 5d14b794dd
1 changed files with 5 additions and 7 deletions

View File

@ -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)
}