feat: support separate authentication for Sentinel and Redis (#888)
* feat: support separate authentication for Sentinel and Redis - Add support for distinct username and password for Sentinel and Redis. - Resolve issues with connecting when Sentinel has no authentication but Redis does. - Handle scenarios where Sentinel and Redis have different authentication configurations. - Improve client logic to dynamically manage authentication based on configuration. BREAKING CHANGE: Requires configuration update to specify separate Sentinel and Redis credentials. * style: redis_standalone_writer.go * fix: sentinel mode no used buff send
This commit is contained in:
parent
5da4fda5fd
commit
d621053eaf
|
@ -8,7 +8,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewRedisSentinelWriter(ctx context.Context, opts *RedisWriterOptions) Writer {
|
func NewRedisSentinelWriter(ctx context.Context, opts *RedisWriterOptions) Writer {
|
||||||
sentinel := client.NewSentinelMasterClient(ctx, opts.Address, opts.Username, opts.Password, opts.Tls)
|
sentinel := client.NewSentinelMasterClient(ctx, opts.Address, opts.SentinelUsername, opts.SentinelPassword, opts.Tls)
|
||||||
sentinel.Send("SENTINEL", "GET-MASTER-ADDR-BY-NAME", opts.Master)
|
sentinel.Send("SENTINEL", "GET-MASTER-ADDR-BY-NAME", opts.Master)
|
||||||
addr, err := sentinel.Receive()
|
addr, err := sentinel.Receive()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -24,6 +24,7 @@ func NewRedisSentinelWriter(ctx context.Context, opts *RedisWriterOptions) Write
|
||||||
Password: opts.Password,
|
Password: opts.Password,
|
||||||
Tls: opts.Tls,
|
Tls: opts.Tls,
|
||||||
OffReply: opts.OffReply,
|
OffReply: opts.OffReply,
|
||||||
|
BuffSend: opts.BuffSend,
|
||||||
}
|
}
|
||||||
log.Infof("connecting to master node at %s", redisOpt.Address)
|
log.Infof("connecting to master node at %s", redisOpt.Address)
|
||||||
return NewRedisStandaloneWriter(ctx, redisOpt)
|
return NewRedisStandaloneWriter(ctx, redisOpt)
|
||||||
|
|
|
@ -18,15 +18,17 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type RedisWriterOptions struct {
|
type RedisWriterOptions struct {
|
||||||
Cluster bool `mapstructure:"cluster" default:"false"`
|
Cluster bool `mapstructure:"cluster" default:"false"`
|
||||||
Sentinel bool `mapstructure:"sentinel" default:"false"`
|
Sentinel bool `mapstructure:"sentinel" default:"false"`
|
||||||
Master string `mapstructure:"master" default:""`
|
Master string `mapstructure:"master" default:""`
|
||||||
Address string `mapstructure:"address" default:""`
|
Address string `mapstructure:"address" default:""`
|
||||||
Username string `mapstructure:"username" default:""`
|
Username string `mapstructure:"username" default:""`
|
||||||
Password string `mapstructure:"password" default:""`
|
Password string `mapstructure:"password" default:""`
|
||||||
Tls bool `mapstructure:"tls" default:"false"`
|
SentinelUsername string `mapstructure:"sentinel_username" default:""`
|
||||||
OffReply bool `mapstructure:"off_reply" default:"false"`
|
SentinelPassword string `mapstructure:"sentinel_password" default:""`
|
||||||
BuffSend bool `mapstructure:"buff_send" default:"false"`
|
Tls bool `mapstructure:"tls" default:"false"`
|
||||||
|
OffReply bool `mapstructure:"off_reply" default:"false"`
|
||||||
|
BuffSend bool `mapstructure:"buff_send" default:"false"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type redisStandaloneWriter struct {
|
type redisStandaloneWriter struct {
|
||||||
|
|
|
@ -34,6 +34,8 @@ master = "" # set to master name if target is a redis sentinel
|
||||||
address = "127.0.0.1:6380" # when cluster is true, set address to one of the cluster node
|
address = "127.0.0.1:6380" # when cluster is true, set address to one of the cluster node
|
||||||
username = "" # keep empty if not using ACL
|
username = "" # keep empty if not using ACL
|
||||||
password = "" # keep empty if no authentication is required
|
password = "" # keep empty if no authentication is required
|
||||||
|
sentinel_username = "" # keep empty if not using sentinel ACL
|
||||||
|
sentinel_password = "" # keep empty if sentinel no authentication is required
|
||||||
tls = false
|
tls = false
|
||||||
off_reply = false # turn off the server reply
|
off_reply = false # turn off the server reply
|
||||||
buff_send = false # buffer send, default false. may be a sync delay when true, but it can greatly improve the speed
|
buff_send = false # buffer send, default false. may be a sync delay when true, but it can greatly improve the speed
|
||||||
|
|
Loading…
Reference in New Issue