正在显示
2 个修改的文件
包含
24 行增加
和
1 行删除
pkg/constant/redis.go
0 → 100644
1 | +package constant | ||
2 | + | ||
3 | +import "os" | ||
4 | + | ||
5 | +var ( | ||
6 | + REDIS_HOST = "127.0.0.1" | ||
7 | + REDIS_PORT = "6379" | ||
8 | + REDIS_AUTH = "" | ||
9 | +) | ||
10 | + | ||
11 | +func init() { | ||
12 | + if os.Getenv("REDIS_HOST") != "" { | ||
13 | + REDIS_HOST = os.Getenv("REDIS_HOST") | ||
14 | + REDIS_AUTH = os.Getenv("REDIS_AUTH") | ||
15 | + } | ||
16 | + if os.Getenv("REDIS_PORT") != "" { | ||
17 | + REDIS_PORT = os.Getenv("REDIS_PORT") | ||
18 | + } | ||
19 | + if _, ok := os.LookupEnv("REDIS_AUTH"); ok { | ||
20 | + REDIS_AUTH = os.Getenv("REDIS_AUTH") | ||
21 | + } | ||
22 | +} |
@@ -2,6 +2,7 @@ package cache | @@ -2,6 +2,7 @@ package cache | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant" | ||
5 | 6 | ||
6 | "github.com/go-redis/redis" | 7 | "github.com/go-redis/redis" |
7 | ) | 8 | ) |
@@ -15,7 +16,7 @@ const ( | @@ -15,7 +16,7 @@ const ( | ||
15 | func InitRedist() *redis.Client { | 16 | func InitRedist() *redis.Client { |
16 | options := redis.Options{ | 17 | options := redis.Options{ |
17 | Network: "tcp", | 18 | Network: "tcp", |
18 | - Addr: fmt.Sprintf("%s:%s", "127.0.0.1", "6379"), | 19 | + Addr: fmt.Sprintf("%s:%s", constant.REDIS_HOST, constant.REDIS_PORT), |
19 | Dialer: nil, | 20 | Dialer: nil, |
20 | OnConnect: nil, | 21 | OnConnect: nil, |
21 | Password: "", | 22 | Password: "", |
-
请 注册 或 登录 后发表评论