fixup go.mod

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2019-10-18 00:00:29 +03:00
parent 3f90baa4de
commit 2766eceb32

View File

@ -11,37 +11,57 @@ type rkv struct {
Client *redis.Client Client *redis.Client
} }
func (r *rkv) Read(key string) (*store.Record, error) { func (r *rkv) Read(keys ...string) ([]*store.Record, error) {
val, err := r.Client.Get(key).Bytes() var records []*store.Record
if err != nil && err == redis.Nil { for _, key := range keys {
return nil, store.ErrNotFound val, err := r.Client.Get(key).Bytes()
} else if err != nil {
return nil, err if err != nil && err == redis.Nil {
return nil, store.ErrNotFound
} else if err != nil {
return nil, err
}
if val == nil {
return nil, store.ErrNotFound
}
d, err := r.Client.TTL(key).Result()
if err != nil {
return nil, err
}
records = append(records, &store.Record{
Key: key,
Value: val,
Expiry: d,
})
} }
if val == nil { return records, nil
return nil, store.ErrNotFound
}
d, err := r.Client.TTL(key).Result()
if err != nil {
return nil, err
}
return &store.Record{
Key: key,
Value: val,
Expiry: d,
}, nil
} }
func (r *rkv) Delete(key string) error { func (r *rkv) Delete(keys ...string) error {
return r.Client.Del(key).Err() var err error
for _, key := range keys {
if err = r.Client.Del(key).Err(); err != nil {
return err
}
}
return nil
} }
func (r *rkv) Write(record *store.Record) error { func (r *rkv) Write(records ...*store.Record) error {
return r.Client.Set(record.Key, record.Value, record.Expiry).Err() var err error
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) Sync() ([]*store.Record, error) { func (r *rkv) Sync() ([]*store.Record, error) {
@ -55,7 +75,7 @@ func (r *rkv) Sync() ([]*store.Record, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
vals = append(vals, i) vals = append(vals, i...)
} }
return vals, nil return vals, nil
} }