Example #1
0
func Hget(key string, field string, to interface{}) error {
	var err error
	defer utils.Regain("redis get falure")
	data := redis.Hget(key, field)

	if data == nil {
		to = nil
		return errors.New("key point value is nil ")
	}
	err = utils.Decode(data.([]byte), to)
	if err != nil {
		log.Redf("decode failure", err)
	}
	return err
}
Example #2
0
func Hset(key string, field string, val interface{}, expire int64) error {
	var err error
	data, err := utils.Encode(val)

	if err != nil {
		return err
	}

	if data == nil {
		return errors.New("cc is nil")
	}

	defer utils.Regain("redis set falure")

	err = redis.Hset(key, field, data, expire)
	if err != nil {
		log.Redf("%v", err)
	}

	return err
}
Example #3
0
func InitRedis() {
	cacheConfig := beego.AppConfig.String("cache")

	log.Greenf("cacheConfig:%v \n", cacheConfig)

	var cc cache.Cache
	if "redis" == cacheConfig {
		var err error

		defer utils.Regain("redis init falure")

		cc, err = cache.NewCache("redis", `{"conn":"`+beego.AppConfig.String("redis_host")+`"}`)

		if err != nil {
			log.Redf("%v", err)
		}
		cache, ok := cc.(*caches.MyRedisCache)
		if ok {
			redis = cache
		} else {
			log.Redf("parse cache to MyRedisCache failure !")
		}
	}
}