rankclean.go
1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"client/sdkdb"
"client/sdkredis"
"common"
"flag"
"fmt"
"log"
"os"
"strings"
)
func main() {
configPath := flag.String("config", "./sdkRoute.conf", "config path")
flag.Parse()
fmt.Printf("config[%v]", *configPath)
config := common.NewConfig(*configPath)
// db初始化
sdkdb.DBInit()
// 注册数据库
dberr := sdkdb.DBRegis(config.DBMysql)
if dberr != nil {
log.Printf("DBRegis err[%v]\n", dberr)
return
}
// 设置数据库日志
sdkdb.SetLogDebug(true, os.Stdout)
// redis 初始化
sdkredis.RedisInit(config)
// 连接redis
redisConn := sdkredis.RedisClient.GetConn()
defer sdkredis.RedisClose(redisConn)
for {
msg, _ := sdkredis.RedisLPop(redisConn, "IsRankClean")
if msg == "clean" {
keys, err := sdkredis.RedisGetKeys(redisConn, "ice_gametop*toptype:[^0]*mykey")
if err != nil {
sdkredis.RedisClose(redisConn)
log.Printf("RedisGetKeys keys[%s] err[%v]\n", keys, err)
continue
}
log.Printf("clean start...")
// redis 更新
for _, key := range keys {
index0 := strings.Index(key, ":gtid:")
index1 := strings.Index(key, ":gid:")
index2 := strings.Index(key, ":toptype:")
index3 := strings.Index(key, ":mykey")
gtid := common.Substr2(key, index0+6, index1)
gid := common.Substr2(key, index1+5, index2)
toptype := common.Substr2(key, index2+9, index3)
//sdkredis.RedisSetKV(redisConn, key, "0")
//sdkredis.RedisZAddSortSet(redisConn, "sortset:gtid:"+gtid+":gid:"+gid+":toptype:"+toptype, 0, key)
log.Printf("del key[%v]", key)
sdkredis.RedisDelKey(redisConn, key)
sdkredis.RedisZSortSetRem(redisConn, "sortset:gtid:"+gtid+":gid:"+gid+":toptype:"+toptype, key)
}
// 数据库更新
sdkdb.IceGameTopCleanScore()
log.Printf("clean end.")
}
}
}