Co-authored-by: 杨羽 <yangyu@doumi.com>
This commit is contained in:
doubleycn@qq.com 2020-06-30 18:07:12 +08:00 committed by Vasiliy Tolstov
parent d6353efc12
commit 7eb9a721f7

View File

@ -33,9 +33,29 @@ func (r *rkv) Read(key string, opts ...store.ReadOption) ([]*store.Record, error
o(&options) o(&options)
} }
records := make([]*store.Record, 0, 1) var keys []string
rkey := fmt.Sprintf("%s%s", options.Table, key) rkey := fmt.Sprintf("%s%s", options.Table, key)
// Handle Prefix
// TODO suffix
if options.Prefix {
prefix_key := fmt.Sprintf("%s*", rkey)
r.Client.Keys(key)
fkeys, err := r.Client.Keys(prefix_key).Result()
if err != nil {
return nil, err
}
// TODO Limit Offset
keys = append(keys, fkeys...)
} else {
keys = []string{rkey}
}
records := make([]*store.Record, 0, len(keys))
for _, rkey = range keys {
val, err := r.Client.Get(rkey).Bytes() val, err := r.Client.Get(rkey).Bytes()
if err != nil && err == redis.Nil { if err != nil && err == redis.Nil {
@ -58,6 +78,7 @@ func (r *rkv) Read(key string, opts ...store.ReadOption) ([]*store.Record, error
Value: val, Value: val,
Expiry: d, Expiry: d,
}) })
}
return records, nil return records, nil
} }