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

Add redis to video-service #77

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add redis to video-service #77

wants to merge 1 commit into from

Conversation

reeered
Copy link
Collaborator

@reeered reeered commented Sep 9, 2023

No description provided.

pkg/redis/redis.go Show resolved Hide resolved
pkg/redis/redis.go Show resolved Hide resolved
"Title": video.Title,
"PlayUrl": video.PlayUrl,
"CoverUrl": video.CoverUrl,
"CreatedAt": video.CreatedAt,
Copy link
Owner

Choose a reason for hiding this comment

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

CreatedAt不需要,只有feed用得上

Copy link
Owner

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
}
Copy link
Owner

Choose a reason for hiding this comment

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

redis没有数据时,应该继续从数据库中拿取

err := rdb.HSet(key, FormatVideoInfo(video, true)).Err()
if err != nil {
return err
}
Copy link
Owner

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
}
Copy link
Owner

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
}
}
Copy link
Owner

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
}
Copy link
Owner

Choose a reason for hiding this comment

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

获取失败从数据库拿

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