Skip to content

Commit f442d05

Browse files
mfadl1Muhammad Fadli Gunardi
andauthored
chore: support the redis cluster type (#56)
Co-authored-by: Muhammad Fadli Gunardi <muhammad.gunardi@gojek.com>
1 parent 81b103d commit f442d05

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

config/redis.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type RedisType = string
1515
const (
1616
RedisTypeSentinel RedisType = "sentinel"
1717
RedisTypeStandalone RedisType = "standalone"
18+
RedisTypeCluster RedisType = "cluster"
1819
)
1920

2021
type redisConfig struct {

ingestionrule/action/dedup/cache/redis.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,29 @@ func NewRedisCache(ctx context.Context, metricPushInterval time.Duration) (redis
5555
MaxRetryBackoff: config.RedisCfg.RetryProperties.MaxRetryBackOff,
5656
PoolSize: config.RedisCfg.PoolSize,
5757
})
58+
case config.RedisTypeCluster:
59+
rawAddrs := strings.Split(config.RedisCfg.Address, ",")
60+
clusterAddrs := make([]string, 0, len(rawAddrs))
61+
for _, addr := range rawAddrs {
62+
trimmed := strings.TrimSpace(addr)
63+
if trimmed != "" {
64+
clusterAddrs = append(clusterAddrs, trimmed)
65+
}
66+
}
67+
68+
if len(clusterAddrs) == 0 {
69+
return nil, errors.New("redis cluster requires at least one address")
70+
}
71+
72+
client = redis.NewClusterClient(&redis.ClusterOptions{
73+
Addrs: clusterAddrs,
74+
MaxRetries: config.RedisCfg.RetryProperties.MaxRetries,
75+
MinRetryBackoff: config.RedisCfg.RetryProperties.MinRetryBackOff,
76+
MaxRetryBackoff: config.RedisCfg.RetryProperties.MaxRetryBackOff,
77+
PoolSize: config.RedisCfg.PoolSize,
78+
Username: config.RedisCfg.Username,
79+
Password: config.RedisCfg.Password,
80+
})
5881
default:
5982
return nil, fmt.Errorf("unsupported or invalid redis deployment type: %q", config.RedisCfg.Type)
6083
}

0 commit comments

Comments
 (0)