29 lines
513 B
Go
29 lines
513 B
Go
package redisdb
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
)
|
|
|
|
// GetValueByKey ...
|
|
func (s Server) GetValueByKey(ctx context.Context, key string) string {
|
|
cmd := s.rdb.Get(ctx, key)
|
|
if cmd == nil {
|
|
return ""
|
|
}
|
|
value, _ := cmd.Result()
|
|
return value
|
|
}
|
|
|
|
// GetJSON ...
|
|
func (s Server) GetJSON(ctx context.Context, key string, result interface{}) (ok bool) {
|
|
v := s.GetValueByKey(ctx, key)
|
|
if v == "" {
|
|
return false
|
|
}
|
|
if err := json.Unmarshal([]byte(v), result); err != nil {
|
|
return false
|
|
}
|
|
return true
|
|
}
|