Skip to content

Commit 5171e70

Browse files
committed
配置连接redis集群
1 parent fc170ad commit 5171e70

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

config.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"DbPassword": "123",
1212
"DbMaxIdleConns": "5",
1313
"DbMaxOpenConns": "100",
14+
"RedisCluster": "false",
1415
"RedisHost": "localhost",
1516
"RedisPort": "6379",
1617
"RedisPassword": ""

k8s.yaml

+9-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,15 @@ spec:
4949
- name: DbUser
5050
value: root
5151
- 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: ""
5461
---
5562
apiVersion: networking.istio.io/v1alpha3
5663
kind: Gateway

workflow-config/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type Configuration struct {
2222
DbPassword string
2323
DbMaxIdleConns string
2424
DbMaxOpenConns string
25+
RedisCluster string
2526
RedisHost string
2627
RedisPort string
2728
RedisPassword string

workflow-engine/model/redis.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,25 @@ import (
88
)
99

1010
// RedisClient redis客户端
11-
var RedisClient *redis.Client
11+
var RedisClient *redis.ClusterClient
1212

1313
// SetRedis 设置redis
1414
func SetRedis() {
1515
var err error
1616
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},
1930
Password: conf.RedisPassword,
2031
})
2132
pong, err := RedisClient.Ping().Result()

0 commit comments

Comments
 (0)