File tree 4 files changed +25
-5
lines changed
4 files changed +25
-5
lines changed Original file line number Diff line number Diff line change 11
11
"DbPassword" : " 123" ,
12
12
"DbMaxIdleConns" : " 5" ,
13
13
"DbMaxOpenConns" : " 100" ,
14
+ "RedisCluster" : " false" ,
14
15
"RedisHost" : " localhost" ,
15
16
"RedisPort" : " 6379" ,
16
17
"RedisPassword" : " "
Original file line number Diff line number Diff line change 49
49
- name : DbUser
50
50
value : root
51
51
- name : DbPassword
52
- value : "123
53
- "
52
+ value : " 123"
53
+ - name : RedisCluster # 是否是redis集群
54
+ value : " true"
55
+ - name : RedisHost
56
+ value : redis-service # redis 集群ip
57
+ - name : RedisPort
58
+ value : " 6379"
59
+ - name : RedisPassword
60
+ value : " "
54
61
---
55
62
apiVersion : networking.istio.io/v1alpha3
56
63
kind : Gateway
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ type Configuration struct {
22
22
DbPassword string
23
23
DbMaxIdleConns string
24
24
DbMaxOpenConns string
25
+ RedisCluster string
25
26
RedisHost string
26
27
RedisPort string
27
28
RedisPassword string
Original file line number Diff line number Diff line change @@ -8,14 +8,25 @@ import (
8
8
)
9
9
10
10
// RedisClient redis客户端
11
- var RedisClient * redis.Client
11
+ var RedisClient * redis.ClusterClient
12
12
13
13
// SetRedis 设置redis
14
14
func SetRedis () {
15
15
var err error
16
16
fmt .Println ("-------启动redis--------" )
17
- RedisClient = redis .NewClient (& redis.Options {
18
- Addr : conf .RedisHost + ":" + conf .RedisPort ,
17
+ // if conf.RedisCluster == "true" {
18
+ // RedisClient = redis.NewClusterClient(&redis.ClusterOptions{
19
+ // Addrs: []string{conf.RedisHost + ":" + conf.RedisPort},
20
+ // Password: conf.RedisPassword,
21
+ // })
22
+ // }else {
23
+ // RedisClient = redis.NewClient(&redis.Options{
24
+ // Addr: conf.RedisHost + ":" + conf.RedisPort,
25
+ // Password: conf.RedisPassword,
26
+ // })
27
+ // }
28
+ RedisClient = redis .NewClusterClient (& redis.ClusterOptions {
29
+ Addrs : []string {conf .RedisHost + ":" + conf .RedisPort },
19
30
Password : conf .RedisPassword ,
20
31
})
21
32
pong , err := RedisClient .Ping ().Result ()
You can’t perform that action at this time.
0 commit comments