package utils import ( "gd_management/common.in/cache" "encoding/json" "errors" "fmt" ) func RedisSet(tabname string, tail string, value interface{}) error { bytes, err := json.Marshal(value) if err != nil { return err } key := fmt.Sprintf("%s-%s", tabname, tail) _, err = cache.Redis.Set(key, string(bytes)) return err } func RedisGetKey(option string) (string, error) { array, err := cache.Redis.Keys(option) if err != nil { return "", err } if len(array) == 0 { return "", errors.New("no record") } return fmt.Sprintf("%s", array[0]), nil } func RedisGet(key string, value interface{}) error { ret, err := cache.Redis.Get(key) if err != nil { return err } if ret == "" { return errors.New("empty") } err = json.Unmarshal([]byte(ret), value) return err } func RedisDelKey(key string) error { _, err := cache.Redis.Del(key) return err }