示例#1
0
文件: redis.go 项目: zombor/galaxy
func (r *RedisBackend) LoadVMap(key string, dest *utils.VersionedMap) error {
	serialized, err := r.GetAll(key)
	if err != nil {
		return err
	}

	dest.UnmarshalMap(serialized)
	return nil
}
示例#2
0
文件: redis.go 项目: zombor/galaxy
func (r *RedisBackend) GcVMap(key string, vmap *utils.VersionedMap) error {
	serialized := vmap.MarshalExpiredMap(5)
	if len(serialized) > 0 {
		keys := []string{}
		for k, _ := range serialized {
			keys = append(keys, k)
		}

		deleted, err := r.DeleteMulti(key, keys...)

		if err != nil {
			return err
		}

		if deleted != 1 {
			return errors.New("not deleted")
		}
	}
	return nil
}
示例#3
0
文件: redis.go 项目: zombor/galaxy
func (r *RedisBackend) SaveVMap(key string, vmap *utils.VersionedMap) error {

	serialized := vmap.MarshalMap()
	if len(serialized) == 0 {
		return nil
	}

	created, err := r.SetMulti(key, serialized)

	if err != nil {
		return err
	}

	if created != "OK" {
		return errors.New("not saved")
	}

	r.GcVMap(key, vmap)
	return nil
}