From ab5ab4c675290c6a89f11fe5265e177d5df4aa58 Mon Sep 17 00:00:00 2001 From: Xiaodong Liu Date: Mon, 30 Oct 2023 20:11:23 +0800 Subject: [PATCH] Add the Protocol attribute to the Redis configuration (#3109) --- contrib/nosql/redis/redis.go | 1 + database/gredis/gredis_config.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/contrib/nosql/redis/redis.go b/contrib/nosql/redis/redis.go index 6be3a2acb73..5240bd8fd27 100644 --- a/contrib/nosql/redis/redis.go +++ b/contrib/nosql/redis/redis.go @@ -61,6 +61,7 @@ func New(config *gredis.Config) *Redis { WriteTimeout: config.WriteTimeout, MasterName: config.MasterName, TLSConfig: config.TLSConfig, + Protocol: config.Protocol, } var client redis.UniversalClient diff --git a/database/gredis/gredis_config.go b/database/gredis/gredis_config.go index 5d804d275f9..caa6808bdd6 100644 --- a/database/gredis/gredis_config.go +++ b/database/gredis/gredis_config.go @@ -40,6 +40,7 @@ type Config struct { TLSConfig *tls.Config `json:"-"` // TLS Config to use. When set TLS will be negotiated. SlaveOnly bool `json:"slaveOnly"` // Route all commands to slave read-only nodes. Cluster bool `json:"cluster"` // Specifies whether cluster mode be used. + Protocol int `json:"protocol"` // Specifies the RESP version (Protocol 2 or 3.) } const ( @@ -102,6 +103,9 @@ func ConfigFromMap(m map[string]interface{}) (config *Config, err error) { if config.MaxConnLifetime < time.Second { config.MaxConnLifetime = config.MaxConnLifetime * time.Second } + if config.Protocol != 2 && config.Protocol != 3 { + config.Protocol = 3 + } return }