Browse Source

调整redis

jiantaoli 4 years ago
parent
commit
4eeb510bc8
3 changed files with 10 additions and 7 deletions
  1. 6 7
      adslib/ads_redis/redis.go
  2. 2 0
      adslib/config.go
  3. 2 0
      conf/config.toml

+ 6 - 7
adslib/ads_redis/redis.go

@@ -2,6 +2,7 @@ package ads_redis
2 2
 
3 3
 import (
4 4
 	"fmt"
5
+	"miads/adslib"
5 6
 	"time"
6 7
 
7 8
 	"github.com/gomodule/redigo/redis"
@@ -9,22 +10,21 @@ import (
9 10
 
10 11
 var RedisConn *redis.Pool
11 12
 
12
-var HOST = ""
13
-var PASSWORD = ""
14
-
15 13
 func Setup() error {
14
+	host := adslib.GetConf().RedisHost
15
+	password := adslib.GetConf().RedisPassword
16 16
 	RedisConn = &redis.Pool{
17 17
 		MaxIdle:     10,
18 18
 		MaxActive:   10,
19 19
 		IdleTimeout: 50,
20 20
 		Dial: func() (redis.Conn, error) {
21
-			c, err := redis.Dial("tcp", HOST)
21
+			c, err := redis.Dial("tcp", host)
22 22
 			if err != nil {
23 23
 				fmt.Println(err)
24 24
 				return nil, err
25 25
 			}
26
-			if PASSWORD != "" {
27
-				if _, err := c.Do("AUTH", PASSWORD); err != nil {
26
+			if password != "" {
27
+				if _, err := c.Do("AUTH", password); err != nil {
28 28
 					fmt.Println(err)
29 29
 					c.Close()
30 30
 					return nil, err
@@ -41,4 +41,3 @@ func Setup() error {
41 41
 
42 42
 	return nil
43 43
 }
44
-

+ 2 - 0
adslib/config.go

@@ -24,6 +24,8 @@ type SvrConf struct {
24 24
 	SecretKey          string                                `toml:"secret_key"`
25 25
 	Ip2RegionFile      string                                `toml:"ip2region_file"`
26 26
 	LogPath            string                                `toml:"log_path"`
27
+	RedisHost          string                                `toml:"redis_host"`
28
+	RedisPassword      string                                `toml:"redis_password"`
27 29
 }
28 30
 type FlogControlItem struct {
29 31
 	Percent  int `toml:"percent"`

+ 2 - 0
conf/config.toml

@@ -10,6 +10,8 @@ freq_control_num = 200
10 10
 secret_key = "%videoopen%!@#$%"
11 11
 ip2region_file = "../conf/ip2region_20200113.db"
12 12
 log_path = "../log"
13
+redis_host="r-wz9sbx1faq7j6zxxgt.redis.rds.aliyuncs.com:6379"
14
+redis_password="3iXAJFuI$J"
13 15
 
14 16
 
15 17
 ## 流量占比控制