@@ -2,6 +2,8 @@ package grpcClient
2
2
3
3
import (
4
4
"context"
5
+ "fmt"
6
+ "gateway-center/cache"
5
7
"gateway-center/pkg/e"
6
8
"gateway-center/util"
7
9
"github.com/OrionLi/douyin-backend/pkg/pb"
@@ -115,15 +117,25 @@ func Feed(ctx context.Context, req *pb.DouyinFeedRequest) ([]*pb.Video, int64, e
115
117
// GetPublishListCount 通过Token获取userId对应的VideoCount
116
118
func GetPublishListCount (ctx context.Context , token string ) (count int64 , err error ) {
117
119
userId := ValidateToken (token )
118
- req := & pb.DouyinPublishListRequest {UserId : userId , Token : token }
119
- r , err := VideoClient .PublishList (ctx , req )
120
- if err != nil {
121
- return 0 , err
122
- }
123
- if r .StatusCode != 0 {
124
- return 0 , e .NewCustomError (int64 (r .StatusCode ), * r .StatusMsg )
125
- }
126
- return int64 (len (r .VideoList )), nil
120
+ PACountKey := fmt .Sprintf ("publishlist:%d" , userId )
121
+ vCount , err := cache .RedisGetKey (ctx , PACountKey )
122
+ if err != nil { //出错,没找到,查询数据库,并写入cache
123
+ util .LogrusObj .Errorf ("Cache get PublishListCount Error ErrorMSG:%s" , err .Error ())
124
+ req := & pb.DouyinPublishListRequest {UserId : userId , Token : token }
125
+ r , err := VideoClient .PublishList (ctx , req )
126
+ if err != nil {
127
+ return 0 , err
128
+ }
129
+ if r .StatusCode != 0 {
130
+ return 0 , e .NewCustomError (int64 (r .StatusCode ), * r .StatusMsg )
131
+ }
132
+ err = cache .RedisSetKey (ctx , PACountKey , int64 (len (r .VideoList )))
133
+ if err != nil {
134
+ util .LogrusObj .Errorf ("Cache set PublishListCount Error ErrorMSG:%s" , err .Error ())
135
+ }
136
+ return int64 (len (r .VideoList )), nil
137
+ } //找到返回结果
138
+ return util .StringToInt64 (vCount ), nil
127
139
}
128
140
129
141
// PublishAction 投稿
0 commit comments