Commit 2e5923b0 authored by Nick Craver's avatar Nick Craver

Misc cleanup (including line endings for some)

parent d5fff16f
...@@ -103,7 +103,7 @@ protected void OnInternalError(object sender, InternalErrorEventArgs e) ...@@ -103,7 +103,7 @@ protected void OnInternalError(object sender, InternalErrorEventArgs e)
} }
private int privateFailCount; private int privateFailCount;
private static AsyncLocal<int> sharedFailCount = new AsyncLocal<int>(); private static readonly AsyncLocal<int> sharedFailCount = new AsyncLocal<int>();
private volatile int expectedFailCount; private volatile int expectedFailCount;
private readonly List<string> privateExceptions = new List<string>(); private readonly List<string> privateExceptions = new List<string>();
......
...@@ -97,8 +97,8 @@ public static bool TryParse(string range, out SlotRange value) ...@@ -97,8 +97,8 @@ public static bool TryParse(string range, out SlotRange value)
/// <param name="other">The other slot range to compare to.</param> /// <param name="other">The other slot range to compare to.</param>
public int CompareTo(SlotRange other) public int CompareTo(SlotRange other)
{ {
int delta = (int)this.from - (int)other.from; int delta = (int)from - (int)other.from;
return delta == 0 ? (int)this.to - (int)other.to : delta; return delta == 0 ? (int)to - (int)other.to : delta;
} }
/// <summary> /// <summary>
...@@ -161,7 +161,7 @@ internal ClusterConfiguration(ServerSelectionStrategy serverSelectionStrategy, s ...@@ -161,7 +161,7 @@ internal ClusterConfiguration(ServerSelectionStrategy serverSelectionStrategy, s
{ {
// Beware: Any exception thrown here will wreak silent havoc like inability to connect to cluster nodes or non returning calls // Beware: Any exception thrown here will wreak silent havoc like inability to connect to cluster nodes or non returning calls
this.serverSelectionStrategy = serverSelectionStrategy; this.serverSelectionStrategy = serverSelectionStrategy;
this.Origin = origin; Origin = origin;
using (var reader = new StringReader(nodes)) using (var reader = new StringReader(nodes))
{ {
string line; string line;
...@@ -178,7 +178,7 @@ internal ClusterConfiguration(ServerSelectionStrategy serverSelectionStrategy, s ...@@ -178,7 +178,7 @@ internal ClusterConfiguration(ServerSelectionStrategy serverSelectionStrategy, s
// make sure that things like clusterConfiguration[clusterConfiguration.Origin] // make sure that things like clusterConfiguration[clusterConfiguration.Origin]
// will work as expected. // will work as expected.
if (node.IsMyself) if (node.IsMyself)
this.Origin = node.EndPoint; Origin = node.EndPoint;
if (nodeLookup.ContainsKey(node.EndPoint)) if (nodeLookup.ContainsKey(node.EndPoint))
{ {
...@@ -286,7 +286,7 @@ internal ClusterNode(ClusterConfiguration configuration, string raw, EndPoint or ...@@ -286,7 +286,7 @@ internal ClusterNode(ClusterConfiguration configuration, string raw, EndPoint or
{ {
// https://redis.io/commands/cluster-nodes // https://redis.io/commands/cluster-nodes
this.configuration = configuration; this.configuration = configuration;
this.Raw = raw; Raw = raw;
var parts = raw.Split(StringSplits.Space); var parts = raw.Split(StringSplits.Space);
var flags = parts[2].Split(StringSplits.Comma); var flags = parts[2].Split(StringSplits.Comma);
...@@ -319,8 +319,7 @@ internal ClusterNode(ClusterConfiguration configuration, string raw, EndPoint or ...@@ -319,8 +319,7 @@ internal ClusterNode(ClusterConfiguration configuration, string raw, EndPoint or
{ {
if (SlotRange.TryParse(parts[i], out SlotRange range)) if (SlotRange.TryParse(parts[i], out SlotRange range))
{ {
if (slots == null) slots = new List<SlotRange>(parts.Length - i); (slots ?? (slots = new List<SlotRange>(parts.Length - i))).Add(range);
slots.Add(range);
} }
} }
Slots = slots?.AsReadOnly() ?? NoSlots; Slots = slots?.AsReadOnly() ?? NoSlots;
...@@ -338,10 +337,9 @@ public IList<ClusterNode> Children ...@@ -338,10 +337,9 @@ public IList<ClusterNode> Children
List<ClusterNode> nodes = null; List<ClusterNode> nodes = null;
foreach (var node in configuration.Nodes) foreach (var node in configuration.Nodes)
{ {
if (node.ParentNodeId == this.NodeId) if (node.ParentNodeId == NodeId)
{ {
if (nodes == null) nodes = new List<ClusterNode>(); (nodes ?? (nodes = new List<ClusterNode>())).Add(node);
nodes.Add(node);
} }
} }
children = nodes?.AsReadOnly() ?? NoNodes; children = nodes?.AsReadOnly() ?? NoNodes;
...@@ -416,14 +414,14 @@ public int CompareTo(ClusterNode other) ...@@ -416,14 +414,14 @@ public int CompareTo(ClusterNode other)
{ {
if (other == null) return -1; if (other == null) return -1;
if (this.IsSlave != other.IsSlave) return IsSlave ? 1 : -1; // masters first if (IsSlave != other.IsSlave) return IsSlave ? 1 : -1; // masters first
if (IsSlave) // both slaves? compare by parent, so we get masters A, B, C and then slaves of A, B, C if (IsSlave) // both slaves? compare by parent, so we get masters A, B, C and then slaves of A, B, C
{ {
int i = string.CompareOrdinal(this.ParentNodeId, other.ParentNodeId); int i = string.CompareOrdinal(ParentNodeId, other.ParentNodeId);
if (i != 0) return i; if (i != 0) return i;
} }
return string.CompareOrdinal(this.NodeId, other.NodeId); return string.CompareOrdinal(NodeId, other.NodeId);
} }
/// <summary> /// <summary>
......
...@@ -8,7 +8,7 @@ namespace StackExchange.Redis ...@@ -8,7 +8,7 @@ namespace StackExchange.Redis
/// </summary> /// </summary>
public abstract class Condition public abstract class Condition
{ {
internal abstract Condition MapKeys(Func<RedisKey,RedisKey> map); internal abstract Condition MapKeys(Func<RedisKey, RedisKey> map);
private Condition() { } private Condition() { }
...@@ -293,7 +293,7 @@ private class ConditionMessage : Message.CommandKeyBase ...@@ -293,7 +293,7 @@ private class ConditionMessage : Message.CommandKeyBase
public ConditionMessage(Condition condition, int db, CommandFlags flags, RedisCommand command, RedisKey key, RedisValue value) public ConditionMessage(Condition condition, int db, CommandFlags flags, RedisCommand command, RedisKey key, RedisValue value)
: base(db, flags, command, key) : base(db, flags, command, key)
{ {
this.Condition = condition; Condition = condition;
this.value = value; // note no assert here this.value = value; // note no assert here
} }
...@@ -322,7 +322,7 @@ internal class ExistsCondition : Condition ...@@ -322,7 +322,7 @@ internal class ExistsCondition : Condition
private readonly RedisType type; private readonly RedisType type;
private readonly RedisCommand cmd; private readonly RedisCommand cmd;
internal override Condition MapKeys(Func<RedisKey,RedisKey> map) internal override Condition MapKeys(Func<RedisKey, RedisKey> map)
{ {
return new ExistsCondition(map(key), type, expectedValue, expectedResult); return new ExistsCondition(map(key), type, expectedValue, expectedResult);
} }
...@@ -335,11 +335,14 @@ public ExistsCondition(RedisKey key, RedisType type, RedisValue expectedValue, b ...@@ -335,11 +335,14 @@ public ExistsCondition(RedisKey key, RedisType type, RedisValue expectedValue, b
this.expectedValue = expectedValue; this.expectedValue = expectedValue;
this.expectedResult = expectedResult; this.expectedResult = expectedResult;
if (expectedValue.IsNull) { if (expectedValue.IsNull)
{
cmd = RedisCommand.EXISTS; cmd = RedisCommand.EXISTS;
} }
else { else
switch (type) { {
switch (type)
{
case RedisType.Hash: case RedisType.Hash:
cmd = RedisCommand.HEXISTS; cmd = RedisCommand.HEXISTS;
break; break;
...@@ -403,7 +406,7 @@ internal override bool TryValidate(RawResult result, out bool value) ...@@ -403,7 +406,7 @@ internal override bool TryValidate(RawResult result, out bool value)
internal class EqualsCondition : Condition internal class EqualsCondition : Condition
{ {
internal override Condition MapKeys(Func<RedisKey,RedisKey> map) internal override Condition MapKeys(Func<RedisKey, RedisKey> map)
{ {
return new EqualsCondition(map(key), hashField, expectedEqual, expectedValue); return new EqualsCondition(map(key), hashField, expectedEqual, expectedValue);
} }
...@@ -467,7 +470,7 @@ internal override bool TryValidate(RawResult result, out bool value) ...@@ -467,7 +470,7 @@ internal override bool TryValidate(RawResult result, out bool value)
internal class ListCondition : Condition internal class ListCondition : Condition
{ {
internal override Condition MapKeys(Func<RedisKey,RedisKey> map) internal override Condition MapKeys(Func<RedisKey, RedisKey> map)
{ {
return new ListCondition(map(key), index, expectedResult, expectedValue); return new ListCondition(map(key), index, expectedResult, expectedValue);
} }
...@@ -535,7 +538,7 @@ internal override bool TryValidate(RawResult result, out bool value) ...@@ -535,7 +538,7 @@ internal override bool TryValidate(RawResult result, out bool value)
internal class LengthCondition : Condition internal class LengthCondition : Condition
{ {
internal override Condition MapKeys(Func<RedisKey,RedisKey> map) internal override Condition MapKeys(Func<RedisKey, RedisKey> map)
{ {
return new LengthCondition(map(key), type, compareToResult, expectedLength); return new LengthCondition(map(key), type, compareToResult, expectedLength);
} }
...@@ -553,7 +556,8 @@ public LengthCondition(RedisKey key, RedisType type, int compareToResult, long e ...@@ -553,7 +556,8 @@ public LengthCondition(RedisKey key, RedisType type, int compareToResult, long e
this.compareToResult = compareToResult; this.compareToResult = compareToResult;
this.expectedLength = expectedLength; this.expectedLength = expectedLength;
this.type = type; this.type = type;
switch (type) { switch (type)
{
case RedisType.Hash: case RedisType.Hash:
cmd = RedisCommand.HLEN; cmd = RedisCommand.HLEN;
break; break;
...@@ -616,7 +620,7 @@ internal override bool TryValidate(RawResult result, out bool value) ...@@ -616,7 +620,7 @@ internal override bool TryValidate(RawResult result, out bool value)
case ResultType.SimpleString: case ResultType.SimpleString:
case ResultType.Integer: case ResultType.Integer:
var parsed = result.AsRedisValue(); var parsed = result.AsRedisValue();
value = parsed.IsInteger && (expectedLength.CompareTo((long) parsed) == compareToResult); value = parsed.IsInteger && (expectedLength.CompareTo((long)parsed) == compareToResult);
ConnectionMultiplexer.TraceWithoutContext("actual: " + (string)parsed + "; expected: " + expectedLength + ConnectionMultiplexer.TraceWithoutContext("actual: " + (string)parsed + "; expected: " + expectedLength +
"; wanted: " + GetComparisonString() + "; voting: " + value); "; wanted: " + GetComparisonString() + "; voting: " + value);
return true; return true;
...@@ -640,7 +644,7 @@ public sealed class ConditionResult ...@@ -640,7 +644,7 @@ public sealed class ConditionResult
internal ConditionResult(Condition condition) internal ConditionResult(Condition condition)
{ {
this.Condition = condition; Condition = condition;
resultBox = ResultBox<bool>.Get(condition); resultBox = ResultBox<bool>.Get(condition);
} }
......
...@@ -98,7 +98,7 @@ internal static string TryGetAzureRoleInstanceIdNoThrow() ...@@ -98,7 +98,7 @@ internal static string TryGetAzureRoleInstanceIdNoThrow()
var currentRoleInstanceId = currentRoleInstanceProp.GetValue(null, null); var currentRoleInstanceId = currentRoleInstanceProp.GetValue(null, null);
roleInstanceId = currentRoleInstanceId.GetType().GetProperty("Id").GetValue(currentRoleInstanceId, null).ToString(); roleInstanceId = currentRoleInstanceId.GetType().GetProperty("Id").GetValue(currentRoleInstanceId, null).ToString();
if (String.IsNullOrEmpty(roleInstanceId)) if (string.IsNullOrEmpty(roleInstanceId))
{ {
roleInstanceId = null; roleInstanceId = null;
} }
...@@ -2050,7 +2050,7 @@ void add(string lk, string sk, string v) ...@@ -2050,7 +2050,7 @@ void add(string lk, string sk, string v)
add("Client-Name", "clientName", ClientName); add("Client-Name", "clientName", ClientName);
add("Server-Endpoint", "serverEndpoint", server.EndPoint.ToString()); add("Server-Endpoint", "serverEndpoint", server.EndPoint.ToString());
var hashSlot = message.GetHashSlot(this.ServerSelectionStrategy); var hashSlot = message.GetHashSlot(ServerSelectionStrategy);
// only add keyslot if its a valid cluster key slot // only add keyslot if its a valid cluster key slot
if (hashSlot != ServerSelectionStrategy.NoSlot) if (hashSlot != ServerSelectionStrategy.NoSlot)
{ {
......
...@@ -943,7 +943,7 @@ private void MatchResult(RawResult result) ...@@ -943,7 +943,7 @@ private void MatchResult(RawResult result)
msg = outstanding.Dequeue(); msg = outstanding.Dequeue();
} }
Multiplexer.Trace("Response to: " + msg.ToString(), physicalName); Multiplexer.Trace("Response to: " + msg, physicalName);
if (msg.ComputeResult(this, result)) if (msg.ComputeResult(this, result))
{ {
Bridge.CompleteSyncOrAsync(msg); Bridge.CompleteSyncOrAsync(msg);
......
...@@ -309,7 +309,7 @@ internal sealed class TimerMessage : Message ...@@ -309,7 +309,7 @@ internal sealed class TimerMessage : Message
public TimerMessage(int db, CommandFlags flags, RedisCommand command, RedisValue value) public TimerMessage(int db, CommandFlags flags, RedisCommand command, RedisValue value)
: base(db, flags, command) : base(db, flags, command)
{ {
this.Watch = Stopwatch.StartNew(); Watch = Stopwatch.StartNew();
this.value = value; this.value = value;
} }
...@@ -1313,7 +1313,7 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes ...@@ -1313,7 +1313,7 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes
return true; return true;
case ResultType.MultiBulk: case ResultType.MultiBulk:
var arr = result.GetItems(); var arr = result.GetItems();
if(arr.Length == 1) if (arr.Length == 1)
{ {
SetResult(message, arr[0].GetString()); SetResult(message, arr[0].GetString());
return true; return true;
......
...@@ -199,7 +199,7 @@ public void SetClusterConfiguration(ClusterConfiguration configuration) ...@@ -199,7 +199,7 @@ public void SetClusterConfiguration(ClusterConfiguration configuration)
multiplexer.Trace("Updating cluster ranges..."); multiplexer.Trace("Updating cluster ranges...");
multiplexer.UpdateClusterRange(configuration); multiplexer.UpdateClusterRange(configuration);
multiplexer.Trace("Resolving genealogy..."); multiplexer.Trace("Resolving genealogy...");
var thisNode = configuration.Nodes.FirstOrDefault(x => x.EndPoint.Equals(this.EndPoint)); var thisNode = configuration.Nodes.FirstOrDefault(x => x.EndPoint.Equals(EndPoint));
if (thisNode != null) if (thisNode != null)
{ {
List<ServerEndPoint> slaves = null; List<ServerEndPoint> slaves = null;
...@@ -212,8 +212,7 @@ public void SetClusterConfiguration(ClusterConfiguration configuration) ...@@ -212,8 +212,7 @@ public void SetClusterConfiguration(ClusterConfiguration configuration)
} }
else if (node.ParentNodeId == thisNode.NodeId) else if (node.ParentNodeId == thisNode.NodeId)
{ {
if (slaves == null) slaves = new List<ServerEndPoint>(); (slaves ?? (slaves = new List<ServerEndPoint>())).Add(multiplexer.GetServerEndPoint(node.EndPoint));
slaves.Add(multiplexer.GetServerEndPoint(node.EndPoint));
} }
} }
Master = master; Master = master;
......
...@@ -185,8 +185,8 @@ internal SocketToken BeginConnect(EndPoint endpoint, ISocketCallback callback, C ...@@ -185,8 +185,8 @@ internal SocketToken BeginConnect(EndPoint endpoint, ISocketCallback callback, C
socket.NoDelay = true; socket.NoDelay = true;
try try
{ {
CompletionType connectCompletionType = CompletionType.Any; var connectCompletionType = CompletionType.Any;
this.ShouldForceConnectCompletionType(ref connectCompletionType); ShouldForceConnectCompletionType(ref connectCompletionType);
var formattedEndpoint = Format.ToString(endpoint); var formattedEndpoint = Format.ToString(endpoint);
var tuple = Tuple.Create(socket, callback); var tuple = Tuple.Create(socket, callback);
......
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