From 94628174c343f6fd6a25e544eedf0b0574614e19 Mon Sep 17 00:00:00 2001 From: "dian.chen" Date: Mon, 27 May 2024 19:02:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=88=E6=8F=90=E4=BA=A4=E4=B8=80=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- proto/common.proto | 2 ++ service/main/redis/redis.go | 12 ++++++++++-- start.sh | 33 +++++++++++++++++++++++++++------ 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/proto/common.proto b/proto/common.proto index 827caa9..72eeba6 100644 --- a/proto/common.proto +++ b/proto/common.proto @@ -99,6 +99,8 @@ message Audience string OpenId = 1; string NickName = 2; string AvatarUrl = 3; + int32 Rank = 4; //排名 + int32 WinningStreak = 5; //连胜 } //排名信息 diff --git a/service/main/redis/redis.go b/service/main/redis/redis.go index e160d32..c4ba0c7 100644 --- a/service/main/redis/redis.go +++ b/service/main/redis/redis.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "github.com/redis/go-redis/v9" + "os" ) type RankInfo struct { @@ -16,7 +17,7 @@ type RankInfo struct { var client *redis.Client func init() { - url := "redis://:adhd@123@101.35.201.220:6379/1?protocol=3" + url := os.Getenv("REDIS_URL") opts, err := redis.ParseURL(url) if err != nil { panic(err) @@ -71,7 +72,7 @@ func SetAudience(data *pb.Audience) { client.Set(ctx, key, string(jsonData), -1) } -func GetAudience(openId string) *pb.Audience { +func GetAudience(appId string, openId string) *pb.Audience { ctx := context.Background() key := fmt.Sprintf("UserData_%s", openId) result, err := client.Get(ctx, key).Result() @@ -83,6 +84,13 @@ func GetAudience(openId string) *pb.Audience { if err != nil { return nil } + scoreKey := fmt.Sprintf("Score_%s", appId) + cmd := client.HGet(ctx, scoreKey, openId) + result, err = cmd.Result() + if err == nil { + + } + return data } diff --git a/start.sh b/start.sh index 830956b..fc884ee 100644 --- a/start.sh +++ b/start.sh @@ -1,10 +1,31 @@ -if [ -f "pid.main" ];then - pid=`cat pid.main` +#stop +if [ -f "pid.main" ]; then + pid=$(cat pid.main) echo "Stop Server main Process Id:$pid" kill $pid rm -f pid.main fi -chmod 777 ./main -"./main" > ./log/main.log 2> ./log/main.error &pid=$! -echo "$pid" > pid.main -echo "main Sever Process Id:$pid" \ No newline at end of file + +version_old=$(git rev-parse origin/master) +git pull +version_new=$(git rev-parse origin/master) + +#go build +if [ "$version_old" != "$version_new" ] || [ ! -f "main" ]; then + echo "new version $version_new" + export PATH=$PATH:/usr/local/go/bin + go build -gcflags "all=-N -l" -o main -mod=vendor cmd/main.go + chmod 777 main +fi + +#create log dir +if [ ! -d "log" ]; then + mkdir log +fi + +#start +export REDIS_URL="redis://:adhd@123@101.35.201.220:6381/2?protocol=3" +"./main" >./log/main.log 2>./log/main.error & +pid=$! +echo "$pid" >pid.main +echo "main Sever Process Id:$pid"