Skip to content

Commit

Permalink
add code
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanvc committed Jan 18, 2024
1 parent c489309 commit 41cff7a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
23 changes: 21 additions & 2 deletions examples/metricapp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,26 @@ type QueryUserReq struct {
Uid int64
}

type Gender int

const (
GenderMale Gender = 1
GenderFemale Gender = 2
)

type UserStatus int

const (
UserStatusNormal UserStatus = 1
)

type UserDto struct {
Uid int64
Uid int64
Gender Gender
Status UserStatus
CreateTime int64
UpdateTime int64
Name string
}

func (u *UserDto) TableName() string {
Expand Down Expand Up @@ -98,6 +116,7 @@ func (controller *userController) QueryUser(c context.Context, req *QueryUserReq
if err != nil {
return nil, err
}
controller.saveUserToCache(c, resp)
return resp, nil
}

Expand All @@ -108,7 +127,7 @@ func (controller *userController) queryUserFromCache(c context.Context, req *Que
c, cancel := context.WithTimeoutCause(c, time.Millisecond*100,
base.New(codes.DeadlineExceeded, "GetFromRedisTimeout").Err())
defer cancel()
err = controller.redisCli.Get(c, rediskey.UserCacheKey(req.Uid), resp)
err = controller.redisCli.Get(c, rediskey.UserCacheKey(req.Uid), &resp)
switch err {
case redis.Nil:
return nil, base.New(codes.NotFound, "UserNotFoundInCache").Err()
Expand Down
9 changes: 0 additions & 9 deletions examples/metricapp/metricapp.sql

This file was deleted.

0 comments on commit 41cff7a

Please sign in to comment.