Store interface fixes

This commit is contained in:
Asim Aslam 2020-02-12 15:53:18 +00:00 committed by Vasiliy Tolstov
parent 768898d373
commit bb3dc26864

View File

@ -10,10 +10,13 @@ type rkv struct {
Client *redis.Client Client *redis.Client
} }
func (r *rkv) Read(keys ...string) ([]*store.Record, error) { func (r *rkv) Init(...store.Option) error {
records := make([]*store.Record, 0, len(keys)) return nil
}
func (r *rkv) Read(key string, opts ...store.ReadOption) ([]*store.Record, error) {
records := make([]*store.Record, 0, 1)
for _, key := range keys {
val, err := r.Client.Get(key).Bytes() val, err := r.Client.Get(key).Bytes()
if err != nil && err == redis.Nil { if err != nil && err == redis.Nil {
@ -36,31 +39,16 @@ func (r *rkv) Read(keys ...string) ([]*store.Record, error) {
Value: val, Value: val,
Expiry: d, Expiry: d,
}) })
}
return records, nil return records, nil
} }
func (r *rkv) Delete(keys ...string) error { func (r *rkv) Delete(key string) error {
var err error return r.Client.Del(key).Err()
for _, key := range keys {
if err = r.Client.Del(key).Err(); err != nil {
return err
}
}
return nil
} }
func (r *rkv) Write(records ...*store.Record) error { func (r *rkv) Write(record *store.Record) error {
var err error return r.Client.Set(record.Key, record.Value, record.Expiry).Err()
for _, record := range records {
err = r.Client.Set(record.Key, record.Value, record.Expiry).Err()
if err != nil {
return err
}
}
return nil
} }
func (r *rkv) List() ([]*store.Record, error) { func (r *rkv) List() ([]*store.Record, error) {