Beispiel #1
0
// Get is the interface implementation
func (r *Redis) Get(k models.Key, m models.Model) error {
	str, err := r.client.Get(k.String()).Result()
	if err != nil {
		return err
	}
	return m.UnmarshalBinary([]byte(str))
}
Beispiel #2
0
// Save is the interface implementation
func (r *Redis) Save(k models.Key, m models.Model) error {
	b, err := m.MarshalBinary()
	if err != nil {
		return err
	}
	return r.client.Set(k.String(), b, time.Duration(0)).Err()
}
Beispiel #3
0
// Get is the interface implementation. Returns ErrNotFound if no such key existed. Callers should pass a pointer to a model so that Get can write the fetched model into it
func (m *Mem) Get(key models.Key, model models.Model) error {
	m.mut.RLock()
	defer m.mut.RUnlock()
	md, ok := m.m[key.String()]
	if !ok {
		return ErrNotFound
	}
	return model.Set(md)
}