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

+ 2 - 0
adslib/config.go

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

+ 2 - 0
conf/config.toml

@@ -10,6 +10,8 @@ freq_control_num = 200
10
 secret_key = "%videoopen%!@#$%"
10
 secret_key = "%videoopen%!@#$%"
11
 ip2region_file = "../conf/ip2region_20200113.db"
11
 ip2region_file = "../conf/ip2region_20200113.db"
12
 log_path = "../log"
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
 ## 流量占比控制