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:
EquentR 2024-11-26 11:36:40 +08:00 committed by GitHub
parent 5da4fda5fd
commit d621053eaf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 10 deletions

View File

@ -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)

View File

@ -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 {

View File

@ -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