-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add redis to video-service #77
base: main
Are you sure you want to change the base?
Conversation
internal/video/pkg/video/video.go
Outdated
"Title": video.Title, | ||
"PlayUrl": video.PlayUrl, | ||
"CoverUrl": video.CoverUrl, | ||
"CreatedAt": video.CreatedAt, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CreatedAt不需要,只有feed用得上
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
缓存需要设置过期时间,避免大量缓存占满内存
videos := make([]*Video, 0) | ||
if err := db.Where("user_id = ?", userId).Find(&videos).Error; err != nil { | ||
keys, err := rdb.Keys("video:*").Result() | ||
if err != nil { | ||
return nil, err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redis没有数据时,应该继续从数据库中拿取
13040eb
to
c6030b0
Compare
752532f
to
64b16d9
Compare
7a8f61b
to
15cd4a7
Compare
err := rdb.HSet(key, FormatVideoInfo(video, true)).Err() | ||
if err != nil { | ||
return err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个错误应该忽略
_, err = rdb.SAdd(setKey, video.Id).Result() | ||
if err != nil { | ||
return err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同
if err != nil { | ||
return nil, err | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里可以一次add多个,videoIds...
videoData, err := rdb.HGetAll(key).Result() | ||
if err != nil { | ||
return nil, err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
获取失败从数据库拿
No description provided.