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