package utils import ( "encoding/json" "errors" "fmt" "gd_vehicle/common.in/cache" ) 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 RedisSetEx(key string, seconds int64, value interface{}) error { bytes, err := json.Marshal(value) if err != nil { return err } _, err = cache.Redis.SetEx(key, seconds, string(bytes)) return err } 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 } func RedisSadd(key string, members ...interface{}) (int64, error){ return cache.Redis.SAdd(key,members...) } func RedisSIsmember(key string, member interface{}) (bool, error) { return cache.Redis.SIsmember(key,member) } func RedisRem(key string, members ...interface{}) (int64, error){ return cache.Redis.SRem(key,members) }