mirror of
https://github.com/hibiken/asynqmon.git
synced 2025-04-19 23:30:12 +08:00
Add clean up of cluster addrs
This commit is contained in:
parent
4ad1a27a4c
commit
ed0d974851
@ -98,8 +98,18 @@ func makeTLSConfig(cfg *Config) *tls.Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func makeRedisConnOpt(cfg *Config) (asynq.RedisConnOpt, error) {
|
func makeRedisConnOpt(cfg *Config) (asynq.RedisConnOpt, error) {
|
||||||
|
cleanUpClusterNodes := func(clusterNodes string) string {
|
||||||
|
clusterNodes = strings.ReplaceAll(clusterNodes, "]", "")
|
||||||
|
clusterNodes = strings.ReplaceAll(clusterNodes, "[", "")
|
||||||
|
clusterNodes = strings.ReplaceAll(clusterNodes, "\"", "")
|
||||||
|
clusterNodes = strings.ReplaceAll(clusterNodes, " ", "")
|
||||||
|
clusterNodes = strings.ReplaceAll(clusterNodes, "\n", "")
|
||||||
|
return clusterNodes
|
||||||
|
}
|
||||||
|
|
||||||
// Connecting to redis-cluster
|
// Connecting to redis-cluster
|
||||||
if len(cfg.RedisClusterNodes) > 0 {
|
if len(cfg.RedisClusterNodes) > 0 {
|
||||||
|
cfg.RedisClusterNodes = cleanUpClusterNodes(cfg.RedisClusterNodes)
|
||||||
return asynq.RedisClusterClientOpt{
|
return asynq.RedisClusterClientOpt{
|
||||||
Addrs: strings.Split(cfg.RedisClusterNodes, ","),
|
Addrs: strings.Split(cfg.RedisClusterNodes, ","),
|
||||||
Password: cfg.RedisPassword,
|
Password: cfg.RedisPassword,
|
||||||
|
@ -119,6 +119,17 @@ func TestMakeRedisConnOpt(t *testing.T) {
|
|||||||
"localhost:5000", "localhost:5001", "localhost:5002", "localhost:5003", "localhost:5004", "localhost:5005"},
|
"localhost:5000", "localhost:5001", "localhost:5002", "localhost:5003", "localhost:5004", "localhost:5005"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "With cluster nodes array",
|
||||||
|
cfg: &Config{
|
||||||
|
RedisClusterNodes: `["localhost:5000", "localhost:5001", "localhost:5002",
|
||||||
|
"localhost:5003", "localhost:5004", "localhost:5005"]`,
|
||||||
|
},
|
||||||
|
want: asynq.RedisClusterClientOpt{
|
||||||
|
Addrs: []string{
|
||||||
|
"localhost:5000", "localhost:5001", "localhost:5002", "localhost:5003", "localhost:5004", "localhost:5005"},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range tests {
|
for _, tc := range tests {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user