Add the Protocol attribute to the Redis configuration (#3109)

This commit is contained in:
Xiaodong Liu
2023-10-30 20:11:23 +08:00
committed by GitHub
parent 3ea61d084e
commit ab5ab4c675
2 changed files with 5 additions and 0 deletions

View File

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

View File

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