获取上一名
All checks were successful
/ build-services (app/auth_service/Dockerfile, auth, auth) (push) Successful in 38s
/ build-services (app/ecpm_service/Dockerfile, ecpm, ecpm) (push) Successful in 37s
/ build-services (app/user_service/Dockerfile, user, user) (push) Successful in 38s
/ build-services (app/ranking_service/Dockerfile, ranking, ranking) (push) Successful in 40s
/ start-services (push) Successful in 4s

This commit is contained in:
xiabin 2025-02-17 17:51:39 +08:00
parent ac005aa95d
commit f37792b13f
7 changed files with 266 additions and 58 deletions

View File

@ -0,0 +1,50 @@
package logic
import (
"context"
"fmt"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/user_service/user"
"strconv"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/internal/svc"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_service/ranking"
"github.com/zeromicro/go-zero/core/logx"
)
type AtomicGetHigherUserLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewAtomicGetHigherUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AtomicGetHigherUserLogic {
return &AtomicGetHigherUserLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *AtomicGetHigherUserLogic) AtomicGetHigherUser(in *ranking.AtomicGetHigherUserRequest) (*ranking.RankingList, error) {
datum, err := l.svcCtx.RedisRanking.AtomicGetHigherUser(l.ctx, fmt.Sprintf("ecpm:rankings:appId:%d:type:%d", in.AppId, in.Type), float64(in.Score))
if err != nil {
return nil, err
}
userId, err := strconv.Atoi(datum.Member.(string))
if err != nil {
return nil, err
}
//查询用户数据FindOne带缓存
userModel, err := l.svcCtx.UserServiceClient.GetUserById(l.ctx, &user.UserId{UserId: uint64(userId)})
if err != nil {
return nil, err
}
return &ranking.RankingList{
Nickname: userModel.Nickname,
Avatar: userModel.Avatar,
Score: uint32(uint64(datum.Score) >> 32),
}, nil
}

View File

@ -53,3 +53,27 @@ func (r *Ranking) IncrScore(ctx context.Context, key, member string, increment f
func (r *Ranking) Remove(ctx context.Context, key string) (err error) {
return r.c.Del(ctx, key).Err()
}
// 使用 Lua 保证原子性操作
var getHigherByScoreScript = redis.NewScript(`
local members = redis.call('ZRANGEBYSCORE', KEYS[1], ARGV[1],'+inf','LIMIT', 0, 1, 'WITHSCORES')
if #members == 0 then return nil end
return members
`)
// AtomicGetHigherUser 获取排行榜的前一名
func (r *Ranking) AtomicGetHigherUser(ctx context.Context, key string, score float64) (data redis.Z, err error) {
s, err := getHigherByScoreScript.Run(ctx, r.c, []string{key}, score).Result()
if err != nil {
return
}
if s == nil {
return
}
data, ok := s.(redis.Z)
if !ok {
err = fmt.Errorf("redis.Z type error")
return
}
return
}

View File

@ -47,3 +47,8 @@ func (s *RankingServiceServer) RemoveRanking(ctx context.Context, in *ranking.Re
l := logic.NewRemoveRankingLogic(ctx, s.svcCtx)
return l.RemoveRanking(in)
}
func (s *RankingServiceServer) AtomicGetHigherUser(ctx context.Context, in *ranking.AtomicGetHigherUserRequest) (*ranking.RankingList, error) {
l := logic.NewAtomicGetHigherUserLogic(ctx, s.svcCtx)
return l.AtomicGetHigherUser(in)
}

View File

@ -540,6 +540,66 @@ func (x *RemoveRankingRequest) GetType() uint32 {
return 0
}
type AtomicGetHigherUserRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
AppId uint32 `protobuf:"varint,1,opt,name=appId,proto3" json:"appId,omitempty"`
Score uint32 `protobuf:"varint,2,opt,name=score,proto3" json:"score,omitempty"`
Type uint32 `protobuf:"varint,3,opt,name=type,proto3" json:"type,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *AtomicGetHigherUserRequest) Reset() {
*x = AtomicGetHigherUserRequest{}
mi := &file_ranking_service_proto_msgTypes[9]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *AtomicGetHigherUserRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*AtomicGetHigherUserRequest) ProtoMessage() {}
func (x *AtomicGetHigherUserRequest) ProtoReflect() protoreflect.Message {
mi := &file_ranking_service_proto_msgTypes[9]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use AtomicGetHigherUserRequest.ProtoReflect.Descriptor instead.
func (*AtomicGetHigherUserRequest) Descriptor() ([]byte, []int) {
return file_ranking_service_proto_rawDescGZIP(), []int{9}
}
func (x *AtomicGetHigherUserRequest) GetAppId() uint32 {
if x != nil {
return x.AppId
}
return 0
}
func (x *AtomicGetHigherUserRequest) GetScore() uint32 {
if x != nil {
return x.Score
}
return 0
}
func (x *AtomicGetHigherUserRequest) GetType() uint32 {
if x != nil {
return x.Type
}
return 0
}
var File_ranking_service_proto protoreflect.FileDescriptor
var file_ranking_service_proto_rawDesc = string([]byte{
@ -593,35 +653,47 @@ var file_ranking_service_proto_rawDesc = string([]byte{
0x65, 0x52, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12,
0x14, 0x0a, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05,
0x61, 0x70, 0x70, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20,
0x01, 0x28, 0x0d, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x32, 0xbc, 0x03, 0x0a, 0x0f, 0x72, 0x61,
0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x3b, 0x0a,
0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, 0x18, 0x2e, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f,
0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
0x19, 0x2e, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63,
0x65, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x59, 0x0a, 0x10, 0x53, 0x65,
0x74, 0x55, 0x73, 0x65, 0x72, 0x47, 0x61, 0x6d, 0x65, 0x53, 0x63, 0x6f, 0x72, 0x65, 0x12, 0x28,
0x2e, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
0x2e, 0x53, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x47, 0x61, 0x6d, 0x65, 0x53, 0x63, 0x6f, 0x72,
0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x72, 0x61, 0x6e, 0x6b, 0x69,
0x6e, 0x67, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x52,
0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x61, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x6b,
0x69, 0x6e, 0x67, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x26, 0x2e, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e,
0x67, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e,
0x6b, 0x69, 0x6e, 0x67, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
0x27, 0x2e, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63,
0x65, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x4c, 0x69, 0x73, 0x74,
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x59, 0x0a, 0x10, 0x41, 0x64, 0x64, 0x55,
0x01, 0x28, 0x0d, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x22, 0x5c, 0x0a, 0x1a, 0x41, 0x74, 0x6f,
0x6d, 0x69, 0x63, 0x47, 0x65, 0x74, 0x48, 0x69, 0x67, 0x68, 0x65, 0x72, 0x55, 0x73, 0x65, 0x72,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64,
0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x12, 0x14, 0x0a,
0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x73, 0x63,
0x6f, 0x72, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28,
0x0d, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x32, 0x9e, 0x04, 0x0a, 0x0f, 0x72, 0x61, 0x6e, 0x6b,
0x69, 0x6e, 0x67, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x3b, 0x0a, 0x04, 0x50,
0x69, 0x6e, 0x67, 0x12, 0x18, 0x2e, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x73, 0x65,
0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e,
0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e,
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x59, 0x0a, 0x10, 0x53, 0x65, 0x74, 0x55,
0x73, 0x65, 0x72, 0x47, 0x61, 0x6d, 0x65, 0x53, 0x63, 0x6f, 0x72, 0x65, 0x12, 0x28, 0x2e, 0x72,
0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x41,
0x64, 0x64, 0x55, 0x73, 0x65, 0x72, 0x47, 0x61, 0x6d, 0x65, 0x53, 0x63, 0x6f, 0x72, 0x65, 0x52,
0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x53,
0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x47, 0x61, 0x6d, 0x65, 0x53, 0x63, 0x6f, 0x72, 0x65, 0x52,
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67,
0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x52, 0x65, 0x73,
0x75, 0x6c, 0x74, 0x12, 0x53, 0x0a, 0x0d, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x52, 0x61, 0x6e,
0x6b, 0x69, 0x6e, 0x67, 0x12, 0x25, 0x2e, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x73,
0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x52, 0x61, 0x6e,
0x6b, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x72, 0x61,
0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x42, 0x61,
0x73, 0x65, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x42, 0x0b, 0x5a, 0x09, 0x2e, 0x2f, 0x72, 0x61,
0x75, 0x6c, 0x74, 0x12, 0x61, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x6b, 0x69, 0x6e,
0x67, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x26, 0x2e, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f,
0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x6b, 0x69,
0x6e, 0x67, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e,
0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e,
0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65,
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x59, 0x0a, 0x10, 0x41, 0x64, 0x64, 0x55, 0x73, 0x65,
0x72, 0x47, 0x61, 0x6d, 0x65, 0x53, 0x63, 0x6f, 0x72, 0x65, 0x12, 0x28, 0x2e, 0x72, 0x61, 0x6e,
0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x41, 0x64, 0x64,
0x55, 0x73, 0x65, 0x72, 0x47, 0x61, 0x6d, 0x65, 0x53, 0x63, 0x6f, 0x72, 0x65, 0x52, 0x65, 0x71,
0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x73,
0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x52, 0x65, 0x73, 0x75, 0x6c,
0x74, 0x12, 0x53, 0x0a, 0x0d, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x52, 0x61, 0x6e, 0x6b, 0x69,
0x6e, 0x67, 0x12, 0x25, 0x2e, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x73, 0x65, 0x72,
0x76, 0x69, 0x63, 0x65, 0x2e, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x52, 0x61, 0x6e, 0x6b, 0x69,
0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x72, 0x61, 0x6e, 0x6b,
0x69, 0x6e, 0x67, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x42, 0x61, 0x73, 0x65,
0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x60, 0x0a, 0x13, 0x41, 0x74, 0x6f, 0x6d, 0x69, 0x63,
0x47, 0x65, 0x74, 0x48, 0x69, 0x67, 0x68, 0x65, 0x72, 0x55, 0x73, 0x65, 0x72, 0x12, 0x2b, 0x2e,
0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e,
0x41, 0x74, 0x6f, 0x6d, 0x69, 0x63, 0x47, 0x65, 0x74, 0x48, 0x69, 0x67, 0x68, 0x65, 0x72, 0x55,
0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x72, 0x61, 0x6e,
0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x52, 0x61, 0x6e,
0x6b, 0x69, 0x6e, 0x67, 0x4c, 0x69, 0x73, 0x74, 0x42, 0x0b, 0x5a, 0x09, 0x2e, 0x2f, 0x72, 0x61,
0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
})
@ -637,17 +709,18 @@ func file_ranking_service_proto_rawDescGZIP() []byte {
return file_ranking_service_proto_rawDescData
}
var file_ranking_service_proto_msgTypes = make([]protoimpl.MessageInfo, 9)
var file_ranking_service_proto_msgTypes = make([]protoimpl.MessageInfo, 10)
var file_ranking_service_proto_goTypes = []any{
(*Request)(nil), // 0: ranking_service.Request
(*Response)(nil), // 1: ranking_service.Response
(*SetUserGameScoreRequest)(nil), // 2: ranking_service.SetUserGameScoreRequest
(*RankingList)(nil), // 3: ranking_service.RankingList
(*GetRankingListResponse)(nil), // 4: ranking_service.GetRankingListResponse
(*GetRankingListRequest)(nil), // 5: ranking_service.GetRankingListRequest
(*BaseResult)(nil), // 6: ranking_service.BaseResult
(*AddUserGameScoreRequest)(nil), // 7: ranking_service.AddUserGameScoreRequest
(*RemoveRankingRequest)(nil), // 8: ranking_service.RemoveRankingRequest
(*Request)(nil), // 0: ranking_service.Request
(*Response)(nil), // 1: ranking_service.Response
(*SetUserGameScoreRequest)(nil), // 2: ranking_service.SetUserGameScoreRequest
(*RankingList)(nil), // 3: ranking_service.RankingList
(*GetRankingListResponse)(nil), // 4: ranking_service.GetRankingListResponse
(*GetRankingListRequest)(nil), // 5: ranking_service.GetRankingListRequest
(*BaseResult)(nil), // 6: ranking_service.BaseResult
(*AddUserGameScoreRequest)(nil), // 7: ranking_service.AddUserGameScoreRequest
(*RemoveRankingRequest)(nil), // 8: ranking_service.RemoveRankingRequest
(*AtomicGetHigherUserRequest)(nil), // 9: ranking_service.AtomicGetHigherUserRequest
}
var file_ranking_service_proto_depIdxs = []int32{
3, // 0: ranking_service.GetRankingListResponse.rankingData:type_name -> ranking_service.RankingList
@ -656,13 +729,15 @@ var file_ranking_service_proto_depIdxs = []int32{
5, // 3: ranking_service.ranking_service.GetRankingList:input_type -> ranking_service.GetRankingListRequest
7, // 4: ranking_service.ranking_service.AddUserGameScore:input_type -> ranking_service.AddUserGameScoreRequest
8, // 5: ranking_service.ranking_service.RemoveRanking:input_type -> ranking_service.RemoveRankingRequest
1, // 6: ranking_service.ranking_service.Ping:output_type -> ranking_service.Response
6, // 7: ranking_service.ranking_service.SetUserGameScore:output_type -> ranking_service.BaseResult
4, // 8: ranking_service.ranking_service.GetRankingList:output_type -> ranking_service.GetRankingListResponse
6, // 9: ranking_service.ranking_service.AddUserGameScore:output_type -> ranking_service.BaseResult
6, // 10: ranking_service.ranking_service.RemoveRanking:output_type -> ranking_service.BaseResult
6, // [6:11] is the sub-list for method output_type
1, // [1:6] is the sub-list for method input_type
9, // 6: ranking_service.ranking_service.AtomicGetHigherUser:input_type -> ranking_service.AtomicGetHigherUserRequest
1, // 7: ranking_service.ranking_service.Ping:output_type -> ranking_service.Response
6, // 8: ranking_service.ranking_service.SetUserGameScore:output_type -> ranking_service.BaseResult
4, // 9: ranking_service.ranking_service.GetRankingList:output_type -> ranking_service.GetRankingListResponse
6, // 10: ranking_service.ranking_service.AddUserGameScore:output_type -> ranking_service.BaseResult
6, // 11: ranking_service.ranking_service.RemoveRanking:output_type -> ranking_service.BaseResult
3, // 12: ranking_service.ranking_service.AtomicGetHigherUser:output_type -> ranking_service.RankingList
7, // [7:13] is the sub-list for method output_type
1, // [1:7] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
1, // [1:1] is the sub-list for extension extendee
0, // [0:1] is the sub-list for field type_name
@ -679,7 +754,7 @@ func file_ranking_service_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_ranking_service_proto_rawDesc), len(file_ranking_service_proto_rawDesc)),
NumEnums: 0,
NumMessages: 9,
NumMessages: 10,
NumExtensions: 0,
NumServices: 1,
},

View File

@ -19,11 +19,12 @@ import (
const _ = grpc.SupportPackageIsVersion9
const (
RankingService_Ping_FullMethodName = "/ranking_service.ranking_service/Ping"
RankingService_SetUserGameScore_FullMethodName = "/ranking_service.ranking_service/SetUserGameScore"
RankingService_GetRankingList_FullMethodName = "/ranking_service.ranking_service/GetRankingList"
RankingService_AddUserGameScore_FullMethodName = "/ranking_service.ranking_service/AddUserGameScore"
RankingService_RemoveRanking_FullMethodName = "/ranking_service.ranking_service/RemoveRanking"
RankingService_Ping_FullMethodName = "/ranking_service.ranking_service/Ping"
RankingService_SetUserGameScore_FullMethodName = "/ranking_service.ranking_service/SetUserGameScore"
RankingService_GetRankingList_FullMethodName = "/ranking_service.ranking_service/GetRankingList"
RankingService_AddUserGameScore_FullMethodName = "/ranking_service.ranking_service/AddUserGameScore"
RankingService_RemoveRanking_FullMethodName = "/ranking_service.ranking_service/RemoveRanking"
RankingService_AtomicGetHigherUser_FullMethodName = "/ranking_service.ranking_service/AtomicGetHigherUser"
)
// RankingServiceClient is the client API for RankingService service.
@ -35,6 +36,7 @@ type RankingServiceClient interface {
GetRankingList(ctx context.Context, in *GetRankingListRequest, opts ...grpc.CallOption) (*GetRankingListResponse, error)
AddUserGameScore(ctx context.Context, in *AddUserGameScoreRequest, opts ...grpc.CallOption) (*BaseResult, error)
RemoveRanking(ctx context.Context, in *RemoveRankingRequest, opts ...grpc.CallOption) (*BaseResult, error)
AtomicGetHigherUser(ctx context.Context, in *AtomicGetHigherUserRequest, opts ...grpc.CallOption) (*RankingList, error)
}
type rankingServiceClient struct {
@ -95,6 +97,16 @@ func (c *rankingServiceClient) RemoveRanking(ctx context.Context, in *RemoveRank
return out, nil
}
func (c *rankingServiceClient) AtomicGetHigherUser(ctx context.Context, in *AtomicGetHigherUserRequest, opts ...grpc.CallOption) (*RankingList, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(RankingList)
err := c.cc.Invoke(ctx, RankingService_AtomicGetHigherUser_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// RankingServiceServer is the server API for RankingService service.
// All implementations must embed UnimplementedRankingServiceServer
// for forward compatibility.
@ -104,6 +116,7 @@ type RankingServiceServer interface {
GetRankingList(context.Context, *GetRankingListRequest) (*GetRankingListResponse, error)
AddUserGameScore(context.Context, *AddUserGameScoreRequest) (*BaseResult, error)
RemoveRanking(context.Context, *RemoveRankingRequest) (*BaseResult, error)
AtomicGetHigherUser(context.Context, *AtomicGetHigherUserRequest) (*RankingList, error)
mustEmbedUnimplementedRankingServiceServer()
}
@ -129,6 +142,9 @@ func (UnimplementedRankingServiceServer) AddUserGameScore(context.Context, *AddU
func (UnimplementedRankingServiceServer) RemoveRanking(context.Context, *RemoveRankingRequest) (*BaseResult, error) {
return nil, status.Errorf(codes.Unimplemented, "method RemoveRanking not implemented")
}
func (UnimplementedRankingServiceServer) AtomicGetHigherUser(context.Context, *AtomicGetHigherUserRequest) (*RankingList, error) {
return nil, status.Errorf(codes.Unimplemented, "method AtomicGetHigherUser not implemented")
}
func (UnimplementedRankingServiceServer) mustEmbedUnimplementedRankingServiceServer() {}
func (UnimplementedRankingServiceServer) testEmbeddedByValue() {}
@ -240,6 +256,24 @@ func _RankingService_RemoveRanking_Handler(srv interface{}, ctx context.Context,
return interceptor(ctx, in, info, handler)
}
func _RankingService_AtomicGetHigherUser_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(AtomicGetHigherUserRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RankingServiceServer).AtomicGetHigherUser(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: RankingService_AtomicGetHigherUser_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RankingServiceServer).AtomicGetHigherUser(ctx, req.(*AtomicGetHigherUserRequest))
}
return interceptor(ctx, in, info, handler)
}
// RankingService_ServiceDesc is the grpc.ServiceDesc for RankingService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
@ -267,6 +301,10 @@ var RankingService_ServiceDesc = grpc.ServiceDesc{
MethodName: "RemoveRanking",
Handler: _RankingService_RemoveRanking_Handler,
},
{
MethodName: "AtomicGetHigherUser",
Handler: _RankingService_AtomicGetHigherUser_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "ranking_service.proto",

View File

@ -57,6 +57,13 @@ message RemoveRankingRequest{
uint32 type = 2;
}
message AtomicGetHigherUserRequest{
uint32 appId = 1;
uint32 score = 2;
uint32 type = 3;
}
service ranking_service {
rpc Ping(Request) returns(Response);
@ -67,4 +74,6 @@ service ranking_service {
rpc AddUserGameScore(AddUserGameScoreRequest) returns(BaseResult);
rpc RemoveRanking(RemoveRankingRequest) returns(BaseResult);
rpc AtomicGetHigherUser(AtomicGetHigherUserRequest) returns(RankingList);
}

View File

@ -14,15 +14,16 @@ import (
)
type (
AddUserGameScoreRequest = ranking.AddUserGameScoreRequest
BaseResult = ranking.BaseResult
GetRankingListRequest = ranking.GetRankingListRequest
GetRankingListResponse = ranking.GetRankingListResponse
RankingList = ranking.RankingList
RemoveRankingRequest = ranking.RemoveRankingRequest
Request = ranking.Request
Response = ranking.Response
SetUserGameScoreRequest = ranking.SetUserGameScoreRequest
AddUserGameScoreRequest = ranking.AddUserGameScoreRequest
AtomicGetHigherUserRequest = ranking.AtomicGetHigherUserRequest
BaseResult = ranking.BaseResult
GetRankingListRequest = ranking.GetRankingListRequest
GetRankingListResponse = ranking.GetRankingListResponse
RankingList = ranking.RankingList
RemoveRankingRequest = ranking.RemoveRankingRequest
Request = ranking.Request
Response = ranking.Response
SetUserGameScoreRequest = ranking.SetUserGameScoreRequest
RankingService interface {
Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
@ -30,6 +31,7 @@ type (
GetRankingList(ctx context.Context, in *GetRankingListRequest, opts ...grpc.CallOption) (*GetRankingListResponse, error)
AddUserGameScore(ctx context.Context, in *AddUserGameScoreRequest, opts ...grpc.CallOption) (*BaseResult, error)
RemoveRanking(ctx context.Context, in *RemoveRankingRequest, opts ...grpc.CallOption) (*BaseResult, error)
AtomicGetHigherUser(ctx context.Context, in *AtomicGetHigherUserRequest, opts ...grpc.CallOption) (*RankingList, error)
}
defaultRankingService struct {
@ -67,3 +69,8 @@ func (m *defaultRankingService) RemoveRanking(ctx context.Context, in *RemoveRan
client := ranking.NewRankingServiceClient(m.cli.Conn())
return client.RemoveRanking(ctx, in, opts...)
}
func (m *defaultRankingService) AtomicGetHigherUser(ctx context.Context, in *AtomicGetHigherUserRequest, opts ...grpc.CallOption) (*RankingList, error) {
client := ranking.NewRankingServiceClient(m.cli.Conn())
return client.AtomicGetHigherUser(ctx, in, opts...)
}