Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat MGet #5

Merged
merged 22 commits into from
Mar 6, 2024
Merged

Feat MGet #5

merged 22 commits into from
Mar 6, 2024

Conversation

daoshenzzg
Copy link
Collaborator

@daoshenzzg daoshenzzg commented Mar 5, 2024

Motivation:

We need to support the function of batch ID querying cache entities. Golang's generics can support this function very conveniently.

Copy link

codecov bot commented Mar 5, 2024

Codecov Report

Attention: Patch coverage is 93.70629% with 9 lines in your changes are missing coverage. Please review.

Project coverage is 90.37%. Comparing base (a983612) to head (8ffd1cf).

Files Patch % Lines
cache.go 93.23% 6 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main       #5      +/-   ##
==========================================
+ Coverage   90.08%   90.37%   +0.29%     
==========================================
  Files           3        3              
  Lines         474      582     +108     
==========================================
+ Hits          427      526      +99     
- Misses         35       41       +6     
- Partials       12       15       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

val, err := strCmd.Result()
if err != nil && !errors.Is(err, r.Nil()) {
logger.Error("MGet#strCmd(%s) error(%v)", keyIdxMap[idx], err)
} else if len(val) > 0 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

万一是空呢,而不是nil

Copy link
Collaborator Author

@daoshenzzg daoshenzzg Mar 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pipeline模式下返回结果,当key不存在,返回的val就是空(""),而不是err=redis.Nil。所以,这里如果val="",作miss处理(但下次查不会穿透)。因此,业务上设置key的value="",在MGet场景该key会miss。

func (r *GoRedisV8Adaptor) MGet(ctx context.Context, keys ...string) (map[string]any, error) {
pipeline := r.client.Pipeline()
keyIdxMap := make(map[int]string, len(keys))
ret := make(map[string]any)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对于这种sdk,最好赋值cap

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK,统一加上,避免扩容。

cache.go Outdated
c.statsHandler.IncrQueryFail(err)
logger.Error("MGet#fn(%s) error(%v)", util.JoinAny(",", ids), err)
} else {
placeholderValues := make(map[string]any)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

设置下cap?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK,统一加上,避免扩容。

@daoshenzzg daoshenzzg merged commit d78b2bb into main Mar 6, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants