// 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)) }
// 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() }
// 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) }
// Delete is the interface implementation. Never returns an error, even if the key didn't exist func (m *Mem) Delete(key models.Key) error { m.mut.Lock() defer m.mut.Unlock() delete(m.m, key.String()) return nil }
// Save is the interface implementation. Overwrites existing keys and never returns an error func (m *Mem) Save(key models.Key, model models.Model) error { m.mut.Lock() defer m.mut.Unlock() m.m[key.String()] = model return nil }
// Delete is the interface implementation func (r *Redis) Delete(k models.Key) error { return r.client.Del(k.String()).Err() }