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,57 +10,45 @@ type rkv struct {
Client *redis.Client
}
func (r *rkv) Read(keys ...string) ([]*store.Record, error) {
records := make([]*store.Record, 0, len(keys))
func (r *rkv) Init(...store.Option) error {
return nil
}
for _, key := range keys {
val, err := r.Client.Get(key).Bytes()
func (r *rkv) Read(key string, opts ...store.ReadOption) ([]*store.Record, error) {
records := make([]*store.Record, 0, 1)
if err != nil && err == redis.Nil {
return nil, store.ErrNotFound
} else if err != nil {
return nil, err
}
val, err := r.Client.Get(key).Bytes()
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 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,
})
return records, nil
}
func (r *rkv) Delete(keys ...string) error {
var err error
for _, key := range keys {
if err = r.Client.Del(key).Err(); err != nil {
return err
}
}
return nil
func (r *rkv) Delete(key string) error {
return r.Client.Del(key).Err()
}
func (r *rkv) Write(records ...*store.Record) error {
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) Write(record *store.Record) error {
return r.Client.Set(record.Key, record.Value, record.Expiry).Err()
}
func (r *rkv) List() ([]*store.Record, error) {