From e92b8de24e0767770630b9154eab6ba4b8dbfa97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A5=B6=E4=B9=90=E4=BD=B3?= Date: Mon, 25 Nov 2024 11:50:53 +0800 Subject: [PATCH] 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. --- internal/writer/redis_sentinel_writer.go | 2 +- internal/writer/redis_standalone_writer.go | 18 ++++++++++-------- shake.toml | 14 ++++++++------ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/internal/writer/redis_sentinel_writer.go b/internal/writer/redis_sentinel_writer.go index 8d3a11bb..2da14dd3 100644 --- a/internal/writer/redis_sentinel_writer.go +++ b/internal/writer/redis_sentinel_writer.go @@ -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 { diff --git a/internal/writer/redis_standalone_writer.go b/internal/writer/redis_standalone_writer.go index ee9b4470..86f0189c 100644 --- a/internal/writer/redis_standalone_writer.go +++ b/internal/writer/redis_standalone_writer.go @@ -18,14 +18,16 @@ 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"` + 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"` } type redisStandaloneWriter struct { diff --git a/shake.toml b/shake.toml index 4c4b146d..5491de32 100644 --- a/shake.toml +++ b/shake.toml @@ -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 @@ -70,8 +72,8 @@ block_db = [] # allow_command = ["GET", "SET"] # Only allow GET and SET commands # block_command = ["DEL", "FLUSHDB"] # Block DEL and FLUSHDB commands # Leave empty to allow all commands -allow_command = [] -block_command = [] +allow_command = [] +block_command = [] # Allow or block specific command groups # Available groups: @@ -82,8 +84,8 @@ block_command = [] # allow_command_group = ["STRING", "HASH"] # Only allow STRING and HASH commands # block_command_group = ["SCRIPTING", "PUBSUB"] # Block SCRIPTING and PUBSUB commands # Leave empty to allow all command groups -allow_command_group = [] -block_command_group = [] +allow_command_group = [] +block_command_group = [] # Function for custom data processing # For best practices and examples, visit: @@ -118,7 +120,7 @@ rdb_restore_command_behavior = "panic" # panic, rewrite or skip pipeline_count_limit = 1024 # This setting corresponds to the 'client-query-buffer-limit' in Redis configuration. -# The default value is typically 1GB. +# The default value is typically 1GB. # It's recommended not to modify this value unless absolutely necessary. target_redis_client_max_querybuf_len = 1073741824 # 1GB in bytes @@ -128,7 +130,7 @@ target_redis_client_max_querybuf_len = 1073741824 # 1GB in bytes # It's recommended not to modify this value unless absolutely necessary. target_redis_proto_max_bulk_len = 512_000_000 -# If the source is Elasticache, you can set this item. AWS ElastiCache has custom +# If the source is Elasticache, you can set this item. AWS ElastiCache has custom # psync command, which can be obtained through a ticket. aws_psync = "" # example: aws_psync = "10.0.0.1:6379@nmfu2sl5osync,10.0.0.1:6379@xhma21xfkssync"