Skip to content

Commit

Permalink
feat: fallback MGetCache to MGet
Browse files Browse the repository at this point in the history
  • Loading branch information
SoulPancake committed Jun 18, 2024
1 parent 4d59a58 commit 7a2c77e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ func MGetCache(client Client, ctx context.Context, ttl time.Duration, keys []str
if len(keys) == 0 {
return make(map[string]RedisMessage), nil
}
if isCacheDisabled(client) {
return MGet(client, ctx, keys)
}
cmds := mgetcachecmdsp.Get(len(keys), len(keys))
defer mgetcachecmdsp.Put(cmds)
for i := range cmds.s {
Expand All @@ -54,6 +57,22 @@ func MGetCache(client Client, ctx context.Context, ttl time.Duration, keys []str
return doMultiCache(client, ctx, cmds.s, keys)
}

func isCacheDisabled(client Client) bool {
switch c := client.(type) {
case *singleClient:
// what do we do here ? @rueian
return false
case *sentinelClient:
if c.mOpt != nil && c.mOpt.DisableCache {
return true
}
if c.sOpt != nil && c.sOpt.DisableCache {
return true
}
}
return false
}

// MGet is a helper that consults the redis directly with multiple keys by grouping keys within same slot into MGET or multiple GETs
func MGet(client Client, ctx context.Context, keys []string) (ret map[string]RedisMessage, err error) {
if len(keys) == 0 {
Expand Down

0 comments on commit 7a2c77e

Please sign in to comment.