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 {
|
||||
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)
|
||||
addr, err := sentinel.Receive()
|
||||
if err != nil {
|
||||
|
@ -24,6 +24,7 @@ func NewRedisSentinelWriter(ctx context.Context, opts *RedisWriterOptions) Write
|
|||
Password: opts.Password,
|
||||
Tls: opts.Tls,
|
||||
OffReply: opts.OffReply,
|
||||
BuffSend: opts.BuffSend,
|
||||
}
|
||||
log.Infof("connecting to master node at %s", redisOpt.Address)
|
||||
return NewRedisStandaloneWriter(ctx, redisOpt)
|
||||
|
|
|
@ -18,15 +18,17 @@ import (
|
|||
)
|
||||
|
||||
type RedisWriterOptions struct {
|
||||
Cluster bool `mapstructure:"cluster" default:"false"`
|
||||
Sentinel bool `mapstructure:"sentinel" default:"false"`
|
||||
Master string `mapstructure:"master" default:""`
|
||||
Address string `mapstructure:"address" default:""`
|
||||
Username string `mapstructure:"username" default:""`
|
||||
Password string `mapstructure:"password" default:""`
|
||||
Tls bool `mapstructure:"tls" default:"false"`
|
||||
OffReply bool `mapstructure:"off_reply" default:"false"`
|
||||
BuffSend bool `mapstructure:"buff_send" default:"false"`
|
||||
Cluster bool `mapstructure:"cluster" default:"false"`
|
||||
Sentinel bool `mapstructure:"sentinel" default:"false"`
|
||||
Master string `mapstructure:"master" default:""`
|
||||
Address string `mapstructure:"address" default:""`
|
||||
Username string `mapstructure:"username" default:""`
|
||||
Password string `mapstructure:"password" default:""`
|
||||
SentinelUsername string `mapstructure:"sentinel_username" default:""`
|
||||
SentinelPassword string `mapstructure:"sentinel_password" default:""`
|
||||
Tls bool `mapstructure:"tls" default:"false"`
|
||||
OffReply bool `mapstructure:"off_reply" default:"false"`
|
||||
BuffSend bool `mapstructure:"buff_send" default:"false"`
|
||||
}
|
||||
|
||||
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
|
||||
username = "" # keep empty if not using ACL
|
||||
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
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue