fixup go.mod
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
3f90baa4de
commit
2766eceb32
36
redis.go
36
redis.go
@ -11,7 +11,10 @@ type rkv struct {
|
||||
Client *redis.Client
|
||||
}
|
||||
|
||||
func (r *rkv) Read(key string) (*store.Record, error) {
|
||||
func (r *rkv) Read(keys ...string) ([]*store.Record, error) {
|
||||
var records []*store.Record
|
||||
|
||||
for _, key := range keys {
|
||||
val, err := r.Client.Get(key).Bytes()
|
||||
|
||||
if err != nil && err == redis.Nil {
|
||||
@ -29,19 +32,36 @@ func (r *rkv) Read(key string) (*store.Record, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &store.Record{
|
||||
records = append(records, &store.Record{
|
||||
Key: key,
|
||||
Value: val,
|
||||
Expiry: d,
|
||||
}, nil
|
||||
})
|
||||
}
|
||||
|
||||
return records, nil
|
||||
}
|
||||
|
||||
func (r *rkv) Delete(key string) error {
|
||||
return r.Client.Del(key).Err()
|
||||
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) Write(record *store.Record) error {
|
||||
return r.Client.Set(record.Key, record.Value, record.Expiry).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) Sync() ([]*store.Record, error) {
|
||||
@ -55,7 +75,7 @@ func (r *rkv) Sync() ([]*store.Record, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
vals = append(vals, i)
|
||||
vals = append(vals, i...)
|
||||
}
|
||||
return vals, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user