Browse Source

调整redis

jiantaoli 4 years ago
parent
commit
aa1005228d
3 changed files with 11 additions and 16 deletions
  1. 1 1
      ads_handler.go
  2. 10 10
      adslib/redis_data/redis_data.go
  3. 0 5
      main.go

+ 1 - 1
ads_handler.go

@@ -138,7 +138,7 @@ func adsHandler(c *gin.Context) {
138 138
 	// 深圳,东莞强行用600秒控制, 其他地区从配置读取
139 139
 	if strings.Index(ipInfo.City, "深圳") == -1 && strings.Index(ipInfo.City, "东莞") == -1 {
140 140
 		// 频率控制
141
-		freqControlConf, err := redis_data.GetFreqCrontolConf(request.ReqSource)
141
+		freqControlConf, err := redis_data.GetFreqControlConf(request.ReqSource)
142 142
 		if err != nil {
143 143
 			log.WithField("request_id", dspInfo.RequestId).Errorf("get freq control conf failed: %s", err)
144 144
 			c.String(404, "get freq control conf failed: %s", err)

+ 10 - 10
adslib/redis_data/redis_data.go

@@ -36,18 +36,18 @@ func (self *FreqControlConf) GetControlTime(hour int) (int, bool) {
36 36
 }
37 37
 
38 38
 // 获取渠道的标记
39
-func GetChannelFlag(reqSource string, business string) (*ChannelFlag, error) {
39
+func GetChannelFlag(reqSource string, business string) (ChannelFlag, error) {
40 40
 	conn := ads_redis.RedisConn.Get()
41 41
 	defer conn.Close()
42 42
 
43 43
 	redisKey := fmt.Sprintf("acfv2_%s_%s", reqSource, business)
44 44
 	rsp, err := conn.Do("GET", redisKey)
45 45
 	if err != nil {
46
-		return nil, err
46
+		return ChannelFlag{}, err
47 47
 	}
48 48
 
49 49
 	if rsp == nil {
50
-		return nil, nil
50
+		return ChannelFlag{}, nil
51 51
 	}
52 52
 
53 53
 	rspBytes, _ := redis.Bytes(rsp, err)
@@ -55,14 +55,14 @@ func GetChannelFlag(reqSource string, business string) (*ChannelFlag, error) {
55 55
 	channelFlag := ChannelFlag{}
56 56
 	err = json.Unmarshal(rspBytes, &channelFlag)
57 57
 	if err != nil {
58
-		return nil, err
58
+		return ChannelFlag{}, err
59 59
 	}
60 60
 
61
-	return &channelFlag, nil
61
+	return channelFlag, nil
62 62
 }
63 63
 
64 64
 // 获取渠道频率信息
65
-func GetFreqCrontolConf(reqSource string) (*FreqControlConf, error) {
65
+func GetFreqControlConf(reqSource string) (FreqControlConf, error) {
66 66
 	conn := ads_redis.RedisConn.Get()
67 67
 	defer conn.Close()
68 68
 
@@ -70,11 +70,11 @@ func GetFreqCrontolConf(reqSource string) (*FreqControlConf, error) {
70 70
 
71 71
 	rsp, err := conn.Do("GET", redisKey)
72 72
 	if err != nil {
73
-		return nil, err
73
+		return FreqControlConf{}, err
74 74
 	}
75 75
 
76 76
 	if rsp == nil {
77
-		return nil, nil
77
+		return FreqControlConf{}, nil
78 78
 	}
79 79
 
80 80
 	rspBytes, _ := redis.Bytes(rsp, err)
@@ -82,10 +82,10 @@ func GetFreqCrontolConf(reqSource string) (*FreqControlConf, error) {
82 82
 	f := FreqControlConf{}
83 83
 	err = json.Unmarshal(rspBytes, &f.confs)
84 84
 	if err != nil {
85
-		return nil, err
85
+		return FreqControlConf{}, err
86 86
 	}
87 87
 
88
-	return &f, nil
88
+	return f, nil
89 89
 }
90 90
 
91 91
 // 获取该广告的总请求次数

+ 0 - 5
main.go

@@ -50,11 +50,6 @@ func main() {
50 50
 	adslib.GetConf()
51 51
 	setupLogger(adslib.GetConf().LogPath+"/ads.log", log.TraceLevel)
52 52
 
53
-	//if ads_redis.RedisConn.ActiveCount() == 0 {
54
-	//	fmt.Printf("setup redis failed, no active redis")
55
-	//	return
56
-	//}
57
-
58 53
 	r := setupRouter()
59 54
 	endless.ListenAndServe(":8080", r)
60 55
 }