Exemplo n.º 1
0
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
}
Exemplo n.º 2
0
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
}
Exemplo n.º 3
0
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
}