Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support separate authentication for Sentinel and Redis #888

Merged
merged 4 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading