Skip to content

Commit

Permalink
feat: support separate authentication for Sentinel and Redis (#888)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
EquentR authored Nov 26, 2024
1 parent 5da4fda commit d621053
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
3 changes: 2 additions & 1 deletion internal/writer/redis_sentinel_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
20 changes: 11 additions & 9 deletions internal/writer/redis_standalone_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions shake.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d621053

Please sign in to comment.