2021-08-09 03:36:09 +00:00
|
|
|
package redisdb
|
|
|
|
|
2022-01-27 03:10:02 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
)
|
2021-08-09 03:36:09 +00:00
|
|
|
|
|
|
|
// GetValueByKey ...
|
|
|
|
func GetValueByKey(ctx context.Context, key string) string {
|
|
|
|
cmd := rdb.Get(ctx, key)
|
|
|
|
if cmd == nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
value, _ := cmd.Result()
|
|
|
|
return value
|
|
|
|
}
|
2022-01-27 03:10:02 +00:00
|
|
|
|
|
|
|
// GetJSON ...
|
|
|
|
func GetJSON(ctx context.Context, key string, result interface{}) (ok bool) {
|
|
|
|
v := GetValueByKey(ctx, key)
|
|
|
|
if v == "" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if err := json.Unmarshal([]byte(v), result); err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|