@@ -19,11 +19,10 @@ func MGetCache(client Client, ctx context.Context, ttl time.Duration, keys []str
1919 return MGet (client , ctx , keys )
2020 }
2121 cmds := mgetcachecmdsp .Get (len (keys ), len (keys ))
22- defer mgetcachecmdsp .Put (cmds )
2322 for i := range cmds .s {
2423 cmds .s [i ] = CT (client .B ().Get ().Key (keys [i ]).Cache (), ttl )
2524 }
26- return doMultiCache (client , ctx , cmds . s , keys )
25+ return doMultiCache (client , ctx , cmds , keys )
2726}
2827
2928func isCacheDisabled (client Client ) bool {
@@ -114,11 +113,10 @@ func JsonMGetCache(client Client, ctx context.Context, ttl time.Duration, keys [
114113 return make (map [string ]RedisMessage ), nil
115114 }
116115 cmds := mgetcachecmdsp .Get (len (keys ), len (keys ))
117- defer mgetcachecmdsp .Put (cmds )
118116 for i := range cmds .s {
119117 cmds .s [i ] = CT (client .B ().JsonGet ().Key (keys [i ]).Path (path ).Cache (), ttl )
120118 }
121- return doMultiCache (client , ctx , cmds . s , keys )
119+ return doMultiCache (client , ctx , cmds , keys )
122120}
123121
124122// JsonMGet is a helper that consults redis directly with multiple keys by grouping keys within the same slot into JSON.MGETs or multiple JSON.GETs
@@ -219,16 +217,17 @@ func clientMDel(client Client, ctx context.Context, keys []string) map[string]er
219217 return ret
220218}
221219
222- func doMultiCache (cc Client , ctx context.Context , cmds [] CacheableTTL , keys []string ) (ret map [string ]RedisMessage , err error ) {
220+ func doMultiCache (cc Client , ctx context.Context , buf * mgetcachecmds , keys []string ) (ret map [string ]RedisMessage , err error ) {
223221 ret = make (map [string ]RedisMessage , len (keys ))
224- resps := cc .DoMultiCache (ctx , cmds ... )
222+ resps := cc .DoMultiCache (ctx , buf . s ... )
225223 defer resultsp .Put (& redisresults {s : resps })
226224 for i , resp := range resps {
227225 if err := resp .NonRedisError (); err != nil {
228226 return nil , err
229227 }
230228 ret [keys [i ]] = resp .val
231229 }
230+ mgetcachecmdsp .Put (buf )
232231 return ret , nil
233232}
234233
0 commit comments