diff --git a/NewLife.Redis/FullRedis.cs b/NewLife.Redis/FullRedis.cs index eb2a321..1a836b6 100644 --- a/NewLife.Redis/FullRedis.cs +++ b/NewLife.Redis/FullRedis.cs @@ -40,8 +40,11 @@ public static FullRedis Create(String config) /// 键前缀 public String? Prefix { get; set; } - /// 自动检测集群节点。默认true - public Boolean AutoDetect { get; set; } = true; + /// 自动检测集群节点。默认false + /// + /// 公有云Redis一般放在代理背后,主从架构,如果开启自动检测,将会自动识别主从,导致得到无法连接的内网主从库地址。 + /// + public Boolean AutoDetect { get; set; } /// 模式 public String? Mode { get; private set; } @@ -115,14 +118,13 @@ public override void Init(String config) if (config.IsNullOrEmpty()) return; - var dic = - config.Contains(',') && !config.Contains(';') ? - config.SplitAsDictionary("=", ",", true) : - config.SplitAsDictionary("=", ";", true); + var dic = ParseConfig(config); if (dic.Count > 0) { - if (dic.TryGetValue("ThrowOnFailure", out var str)) - ThrowOnFailure = str.ToBoolean(); + if (dic.TryGetValue("Prefix", out var str)) + Prefix = str; + if (dic.TryGetValue("AutoDetect", out str)) + AutoDetect = str.ToBoolean(); } _configOld = config; diff --git a/NewLife.Redis/Redis.cs b/NewLife.Redis/Redis.cs index da2edca..484991e 100644 --- a/NewLife.Redis/Redis.cs +++ b/NewLife.Redis/Redis.cs @@ -202,10 +202,7 @@ public override void Init(String config) if (pk != null && pk.Secret != null) connStr = pk.Unprotect(connStr); // 默认分号分割,旧版逗号分隔。可能只有一个server=后续多个含逗号的地址 - var dic = - connStr.Contains(';') || connStr.Split('=').Length <= 2 ? - connStr.SplitAsDictionary("=", ";", true) : - connStr.SplitAsDictionary("=", ",", true); + var dic = ParseConfig(connStr); if (dic.Count > 0) { Server = dic["Server"]?.Trim(); @@ -249,6 +246,20 @@ public override void Init(String config) _configOld = config; } + /// 分析配置连接字符串 + /// + /// + protected IDictionary ParseConfig(String connStr) + { + // 默认分号分割,旧版逗号分隔。可能只有一个server=后续多个含逗号的地址 + var dic = + connStr.Contains(';') || connStr.Split('=').Length <= 2 ? + connStr.SplitAsDictionary("=", ";", true) : + connStr.SplitAsDictionary("=", ",", true); + + return dic; + } + void IConfigMapping.MapConfig(IConfigProvider provider, IConfigSection section) { if (section != null && section.Value != null) Init(section.Value);