Skip to content

Commit

Permalink
fix redis decode, fix get multi
Browse files Browse the repository at this point in the history
  • Loading branch information
acoshift committed Apr 9, 2017
1 parent 6d48f7b commit 3e9e0cd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cache/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (cache *Cache) GetMulti(keys []*datastore.Key, dst interface{}) error {
return err
}
if len(b) > 0 {
decode(b, reflect.Indirect(reflect.ValueOf(dst)).Index(i).Interface())
decode(b, reflect.Indirect(reflect.ValueOf(dst)).Index(i).Addr().Interface())
}
}
if cache.ExtendTTL {
Expand Down
14 changes: 10 additions & 4 deletions get.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ func (client *Client) GetByKeys(ctx context.Context, keys []*datastore.Key, dst
dst = rs.Interface()
}

if len(keys) == 0 {
return nil
}

if client.Cache != nil {
err := client.Cache.GetMulti(keys, dst)
if err == nil {
Expand All @@ -88,10 +92,12 @@ func (client *Client) GetByKeys(ctx context.Context, keys []*datastore.Key, dst
}
}
l := len(nfKeys)
nfDstRf := reflect.MakeSlice(rf.Type(), l, l)
err := client.getByKeys(ctx, keys, nfDstRf.Interface())
for i, k := range nfMap {
rf.Index(k).Set(nfDstRf.Index(i))
if l > 0 {
nfDstRf := reflect.MakeSlice(rf.Type(), l, l)
err = client.getByKeys(ctx, nfKeys, nfDstRf.Interface())
for i, k := range nfMap {
rf.Index(k).Set(nfDstRf.Index(i))
}
}
SetKeys(keys, dst)
if err != nil {
Expand Down

0 comments on commit 3e9e0cd

Please sign in to comment.