Commit 9f0442b6 authored by Marc Gravell's avatar Marc Gravell

Merge branch 'patch-1' of https://github.com/stas-sultanov/StackExchange.Redis...

Merge branch 'patch-1' of https://github.com/stas-sultanov/StackExchange.Redis into stas-sultanov-patch-1

Conflicts:
	StackExchange.Redis/StackExchange/Redis/ConfigurationOptions.cs

Note: tweaked a bit
parent 01b1ba66
...@@ -263,8 +263,10 @@ public CommandMap CommandMap ...@@ -263,8 +263,10 @@ public CommandMap CommandMap
/// <summary> /// <summary>
/// Parse the configuration from a comma-delimited configuration string /// Parse the configuration from a comma-delimited configuration string
/// </summary> /// </summary>
/// <exception cref="ArgumentNullException"><paramref name="configuration"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentException"><paramref name="configuration"/> is empty.</exception>
public static ConfigurationOptions Parse(string configuration) public static ConfigurationOptions Parse(string configuration)
{ {
var options = new ConfigurationOptions(); var options = new ConfigurationOptions();
options.DoParse(configuration, false); options.DoParse(configuration, false);
return options; return options;
...@@ -272,6 +274,8 @@ public static ConfigurationOptions Parse(string configuration) ...@@ -272,6 +274,8 @@ public static ConfigurationOptions Parse(string configuration)
/// <summary> /// <summary>
/// Parse the configuration from a comma-delimited configuration string /// Parse the configuration from a comma-delimited configuration string
/// </summary> /// </summary>
/// <exception cref="ArgumentNullException"><paramref name="configuration"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentException"><paramref name="configuration"/> is empty.</exception>
public static ConfigurationOptions Parse(string configuration, bool ignoreUnknown) public static ConfigurationOptions Parse(string configuration, bool ignoreUnknown)
{ {
var options = new ConfigurationOptions(); var options = new ConfigurationOptions();
...@@ -456,110 +460,118 @@ void Clear() ...@@ -456,110 +460,118 @@ void Clear()
private void DoParse(string configuration, bool ignoreUnknown) private void DoParse(string configuration, bool ignoreUnknown)
{ {
if (configuration == null)
{
throw new ArgumentNullException("configuration");
}
if (string.IsNullOrWhiteSpace(configuration))
{
throw new ArgumentException("is empty", configuration);
}
Clear(); Clear();
if (!string.IsNullOrWhiteSpace(configuration))
// break it down by commas
var arr = configuration.Split(StringSplits.Comma);
Dictionary<string, string> map = null;
foreach (var paddedOption in arr)
{ {
// break it down by commas var option = paddedOption.Trim();
var arr = configuration.Split(StringSplits.Comma);
Dictionary<string, string> map = null;
foreach (var paddedOption in arr)
{
var option = paddedOption.Trim();
if (string.IsNullOrWhiteSpace(option)) continue; if (string.IsNullOrWhiteSpace(option)) continue;
// check for special tokens // check for special tokens
int idx = option.IndexOf('='); int idx = option.IndexOf('=');
if (idx > 0) if (idx > 0)
{ {
var key = option.Substring(0, idx).Trim(); var key = option.Substring(0, idx).Trim();
var value = option.Substring(idx + 1).Trim(); var value = option.Substring(idx + 1).Trim();
switch (OptionKeys.TryNormalize(key)) switch (OptionKeys.TryNormalize(key))
{ {
case OptionKeys.SyncTimeout: case OptionKeys.SyncTimeout:
SyncTimeout = OptionKeys.ParseInt32(key, value, minValue: 1); SyncTimeout = OptionKeys.ParseInt32(key, value, minValue: 1);
break; break;
case OptionKeys.AllowAdmin: case OptionKeys.AllowAdmin:
AllowAdmin = OptionKeys.ParseBoolean(key, value); AllowAdmin = OptionKeys.ParseBoolean(key, value);
break; break;
case OptionKeys.AbortOnConnectFail: case OptionKeys.AbortOnConnectFail:
AbortOnConnectFail = OptionKeys.ParseBoolean(key, value); AbortOnConnectFail = OptionKeys.ParseBoolean(key, value);
break; break;
case OptionKeys.ResolveDns: case OptionKeys.ResolveDns:
ResolveDns = OptionKeys.ParseBoolean(key, value); ResolveDns = OptionKeys.ParseBoolean(key, value);
break; break;
case OptionKeys.ServiceName: case OptionKeys.ServiceName:
ServiceName = value; ServiceName = value;
break; break;
case OptionKeys.ClientName: case OptionKeys.ClientName:
ClientName = value; ClientName = value;
break; break;
case OptionKeys.ChannelPrefix: case OptionKeys.ChannelPrefix:
ChannelPrefix = value; ChannelPrefix = value;
break; break;
case OptionKeys.ConfigChannel: case OptionKeys.ConfigChannel:
ConfigurationChannel = value; ConfigurationChannel = value;
break; break;
case OptionKeys.KeepAlive: case OptionKeys.KeepAlive:
KeepAlive = OptionKeys.ParseInt32(key, value); KeepAlive = OptionKeys.ParseInt32(key, value);
break; break;
case OptionKeys.ConnectTimeout: case OptionKeys.ConnectTimeout:
ConnectTimeout = OptionKeys.ParseInt32(key, value); ConnectTimeout = OptionKeys.ParseInt32(key, value);
break; break;
case OptionKeys.ConnectRetry: case OptionKeys.ConnectRetry:
ConnectRetry = OptionKeys.ParseInt32(key, value); ConnectRetry = OptionKeys.ParseInt32(key, value);
break; break;
case OptionKeys.Version: case OptionKeys.Version:
DefaultVersion = OptionKeys.ParseVersion(key, value); DefaultVersion = OptionKeys.ParseVersion(key, value);
break; break;
case OptionKeys.Password: case OptionKeys.Password:
Password = value; Password = value;
break; break;
case OptionKeys.TieBreaker: case OptionKeys.TieBreaker:
TieBreaker = value; TieBreaker = value;
break; break;
case OptionKeys.Ssl: case OptionKeys.Ssl:
Ssl = OptionKeys.ParseBoolean(key, value); Ssl = OptionKeys.ParseBoolean(key, value);
break; break;
case OptionKeys.SslHost: case OptionKeys.SslHost:
SslHost = value; SslHost = value;
break; break;
case OptionKeys.WriteBuffer: case OptionKeys.WriteBuffer:
WriteBuffer = OptionKeys.ParseInt32(key, value); WriteBuffer = OptionKeys.ParseInt32(key, value);
break; break;
case OptionKeys.Proxy: case OptionKeys.Proxy:
Proxy = OptionKeys.ParseProxy(key, value); Proxy = OptionKeys.ParseProxy(key, value);
break; break;
default: default:
if (!string.IsNullOrEmpty(key) && key[0] == '$') if (!string.IsNullOrEmpty(key) && key[0] == '$')
{ {
RedisCommand cmd; RedisCommand cmd;
var cmdName = option.Substring(1, idx - 1); var cmdName = option.Substring(1, idx - 1);
if (Enum.TryParse(cmdName, true, out cmd)) if (Enum.TryParse(cmdName, true, out cmd))
{
if (map == null) map = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
map[cmdName] = value;
}
}
else
{ {
if(!ignoreUnknown) OptionKeys.Unknown(key); if (map == null) map = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
map[cmdName] = value;
} }
break; }
} else
} {
else if(!ignoreUnknown) OptionKeys.Unknown(key);
{ }
var ep = Format.TryParseEndPoint(option); break;
if (ep != null && !endpoints.Contains(ep)) endpoints.Add(ep);
} }
} }
if (map != null && map.Count != 0) else
{ {
this.CommandMap = CommandMap.Create(map); var ep = Format.TryParseEndPoint(option);
if (ep != null && !endpoints.Contains(ep)) endpoints.Add(ep);
} }
} }
if (map != null && map.Count != 0)
{
this.CommandMap = CommandMap.Create(map);
}
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment