Commit 17a6ced7 authored by Nick Craver's avatar Nick Craver

Cleanup analyzer warnings, exceptions, and param mismatches

parent 9180b523
......@@ -254,7 +254,8 @@ public void GetInfo()
var info2 = server.Info("cpu");
Assert.Single(info2);
var cpu = info2.Single();
Assert.True(cpu.Count() > 2);
var cpuCount = cpu.Count();
Assert.True(cpuCount > 2);
Assert.Equal("CPU", cpu.Key);
Assert.Contains(cpu, x => x.Key == "used_cpu_sys");
Assert.Contains(cpu, x => x.Key == "used_cpu_user");
......
......@@ -112,9 +112,9 @@ public override bool Equals(object obj)
/// <summary>
/// Indicates whether two ranges are equal
/// </summary>
public bool Equals(SlotRange range)
public bool Equals(SlotRange other)
{
return range.from == this.from && range.to == this.to;
return other.from == this.from && other.to == this.to;
}
/// <summary>
......@@ -456,11 +456,11 @@ public override bool Equals(object obj)
/// <summary>
/// Indicates whether two ClusterNode instances are equivalent
/// </summary>
public bool Equals(ClusterNode node)
public bool Equals(ClusterNode other)
{
if (node == null) return false;
if (other == null) return false;
return this.ToString() == node.ToString(); // lazy, but effective - plus only computes once
return this.ToString() == other.ToString(); // lazy, but effective - plus only computes once
}
/// <summary>
......
......@@ -285,8 +285,8 @@ public enum CompletionType
/// </summary>
Async = 2
}
#if FEATURE_PERFCOUNTER
#if FEATURE_PERFCOUNTER
internal static class PerfCounterHelper
{
private static readonly object staticLock = new object();
......@@ -334,7 +334,7 @@ public static bool TryGetSystemCPU(out float value)
}
#endif
#if FEATURE_THREADPOOL
internal class CompletionTypeHelper
internal static class CompletionTypeHelper
{
public static void RunWithCompletionType(Func<AsyncCallback, IAsyncResult> beginAsync, AsyncCallback callback, CompletionType completionType)
{
......
using System;
#if FEATURE_SERIALIZATION
using System.Runtime.Serialization;
#endif
#pragma warning disable RCS1194 // Implement exception constructors.
namespace StackExchange.Redis
{
#if FEATURE_SERIALIZATION
[Serializable]
public sealed partial class RedisCommandException : Exception
{
private RedisCommandException(SerializationInfo info, StreamingContext ctx) : base(info, ctx) { }
}
[Serializable]
public sealed partial class RedisTimeoutException : TimeoutException
{
private RedisTimeoutException(SerializationInfo info, StreamingContext ctx) : base(info, ctx)
{
Commandstatus = (CommandStatus)info.GetValue("commandStatus", typeof(CommandStatus));
}
/// <summary>
/// Serialization implementation; not intended for general usage
/// </summary>
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue("commandStatus", Commandstatus);
}
}
[Serializable]
public sealed partial class RedisConnectionException : RedisException
{
private RedisConnectionException(SerializationInfo info, StreamingContext ctx) : base(info, ctx)
{
FailureType = (ConnectionFailureType)info.GetInt32("failureType");
CommandStatus = (CommandStatus)info.GetValue("commandStatus", typeof(CommandStatus));
}
/// <summary>
/// Serialization implementation; not intended for general usage
/// </summary>
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue("failureType", (int)FailureType);
info.AddValue("commandStatus", CommandStatus);
}
}
[Serializable]
public partial class RedisException : Exception
{
/// <summary>
/// Deserialization constructor; not intended for general usage
/// </summary>
protected RedisException(SerializationInfo info, StreamingContext ctx) : base(info, ctx) { }
}
[Serializable]
public sealed partial class RedisServerException : RedisException
{
private RedisServerException(SerializationInfo info, StreamingContext ctx) : base(info, ctx) { }
}
#endif
/// <summary>
/// Indicates that a command was illegal and was not sent to the server
/// </summary>
public sealed partial class RedisCommandException : Exception
{
internal RedisCommandException(string message) : base(message) { }
internal RedisCommandException(string message, Exception innerException) : base(message, innerException) { }
}
/// <summary>
/// Indicates the time allotted for a command or operation has expired.
/// </summary>
public sealed partial class RedisTimeoutException : TimeoutException
{
internal RedisTimeoutException(string message, CommandStatus commandStatus) : base(message)
{
Commandstatus = commandStatus;
}
/// <summary>
/// status of the command while communicating with Redis
/// </summary>
public CommandStatus Commandstatus { get; }
}
/// <summary>
/// Indicates a connection fault when communicating with redis
/// </summary>
public sealed partial class RedisConnectionException : RedisException
{
internal RedisConnectionException(ConnectionFailureType failureType, string message) : this(failureType, message, null, CommandStatus.Unknown) {}
internal RedisConnectionException(ConnectionFailureType failureType, string message, Exception innerException) : this(failureType, message, innerException, CommandStatus.Unknown) {}
internal RedisConnectionException(ConnectionFailureType failureType, string message, Exception innerException, CommandStatus commandStatus) : base(message, innerException)
{
FailureType = failureType;
CommandStatus = commandStatus;
}
/// <summary>
/// The type of connection failure
/// </summary>
public ConnectionFailureType FailureType { get; }
/// <summary>
/// status of the command while communicating with Redis
/// </summary>
public CommandStatus CommandStatus { get; }
}
/// <summary>
/// Indicates an issue communicating with redis
/// </summary>
public partial class RedisException : Exception
{
internal RedisException(string message) : base(message) { }
internal RedisException(string message, Exception innerException) : base(message, innerException) { }
}
/// <summary>
/// Indicates an exception raised by a redis server
/// </summary>
public sealed partial class RedisServerException : RedisException
{
internal RedisServerException(string message) : base(message) { }
}
}
......@@ -139,9 +139,9 @@ public override bool Equals(object obj)
/// <summary>
/// Compares two values for equality
/// </summary>
public bool Equals(GeoPosition value)
public bool Equals(GeoPosition other)
{
return this == value;
return this == other;
}
/// <summary>
/// Compares two values for equality
......@@ -220,9 +220,9 @@ public override bool Equals(object obj)
/// <summary>
/// Compares two values for equality
/// </summary>
public bool Equals(GeoEntry value)
public bool Equals(GeoEntry other)
{
return this == value;
return this == other;
}
/// <summary>
/// Compares two values for equality
......
......@@ -76,9 +76,9 @@ public override bool Equals(object obj)
/// <summary>
/// Compares two values for equality
/// </summary>
public bool Equals(HashEntry value)
public bool Equals(HashEntry other)
{
return name == value.name && this.value == value.value;
return name == other.name && this.value == other.value;
}
/// <summary>
/// Compares two values for equality
......
......@@ -32,13 +32,13 @@ public bool GeoAdd(RedisKey key, double longitude, double latitude, RedisValue m
return Inner.GeoAdd(ToInner(key), longitude, latitude, member, flags);
}
public long GeoAdd(RedisKey key, GeoEntry[] geoEntries, CommandFlags flags = CommandFlags.None)
public long GeoAdd(RedisKey key, GeoEntry[] values, CommandFlags flags = CommandFlags.None)
{
return Inner.GeoAdd(ToInner(key), geoEntries, flags);
return Inner.GeoAdd(ToInner(key), values, flags);
}
public bool GeoAdd(RedisKey key, GeoEntry geoEntry, CommandFlags flags = CommandFlags.None)
public bool GeoAdd(RedisKey key, GeoEntry value, CommandFlags flags = CommandFlags.None)
{
return Inner.GeoAdd(ToInner(key), geoEntry, flags);
return Inner.GeoAdd(ToInner(key), value, flags);
}
public bool GeoRemove(RedisKey key, RedisValue member, CommandFlags flags = CommandFlags.None)
......@@ -46,9 +46,9 @@ public bool GeoRemove(RedisKey key, RedisValue member, CommandFlags flags = Comm
return Inner.GeoRemove(ToInner(key), member, flags);
}
public double? GeoDistance(RedisKey key, RedisValue value0, RedisValue value1, GeoUnit unit = GeoUnit.Meters,CommandFlags flags = CommandFlags.None)
public double? GeoDistance(RedisKey key, RedisValue member1, RedisValue member2, GeoUnit unit = GeoUnit.Meters,CommandFlags flags = CommandFlags.None)
{
return Inner.GeoDistance(ToInner(key), value0, value1, unit, flags);
return Inner.GeoDistance(ToInner(key), member1, member2, unit, flags);
}
public string[] GeoHash(RedisKey key, RedisValue[] members, CommandFlags flags = CommandFlags.None)
......
......@@ -2,149 +2,12 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
#if FEATURE_SERIALIZATION
using System.Runtime.Serialization;
#endif
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StackExchange.Redis
{
/// <summary>
/// Indicates that a command was illegal and was not sent to the server
/// </summary>
#if FEATURE_SERIALIZATION
[Serializable]
#endif
public sealed class RedisCommandException : Exception
{
#if FEATURE_SERIALIZATION
private RedisCommandException(SerializationInfo info, StreamingContext ctx) : base(info, ctx) { }
#endif
internal RedisCommandException(string message) : base(message) { }
internal RedisCommandException(string message, Exception innerException) : base(message, innerException) { }
}
/// <summary>
/// Indicates the time allotted for a command or operation has expired.
/// </summary>
#if FEATURE_SERIALIZATION
[Serializable]
#endif
public sealed class RedisTimeoutException : TimeoutException
{
#if FEATURE_SERIALIZATION
private RedisTimeoutException(SerializationInfo info, StreamingContext ctx) : base(info, ctx)
{
Commandstatus = (CommandStatus) info.GetValue("commandStatus", typeof(CommandStatus));
}
/// <summary>
/// Serialization implementation; not intended for general usage
/// </summary>
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue("commandStatus", Commandstatus);
}
#endif
internal RedisTimeoutException(string message, CommandStatus commandStatus) : base(message)
{
Commandstatus = commandStatus;
}
/// <summary>
/// status of the command while communicating with Redis
/// </summary>
public CommandStatus Commandstatus { get; }
}
/// <summary>
/// Indicates a connection fault when communicating with redis
/// </summary>
#if FEATURE_SERIALIZATION
[Serializable]
#endif
public sealed class RedisConnectionException : RedisException
{
#if FEATURE_SERIALIZATION
private RedisConnectionException(SerializationInfo info, StreamingContext ctx) : base(info, ctx)
{
FailureType = (ConnectionFailureType)info.GetInt32("failureType");
CommandStatus = (CommandStatus)info.GetValue("commandStatus", typeof(CommandStatus));
}
/// <summary>
/// Serialization implementation; not intended for general usage
/// </summary>
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue("failureType", (int)FailureType);
info.AddValue("commandStatus", CommandStatus);
}
#endif
internal RedisConnectionException(ConnectionFailureType failureType, string message) : this(failureType, message, null, CommandStatus.Unknown)
{
}
internal RedisConnectionException(ConnectionFailureType failureType, string message, Exception innerException) : this(failureType, message, innerException, CommandStatus.Unknown)
{
}
internal RedisConnectionException(ConnectionFailureType failureType, string message, Exception innerException, CommandStatus commandStatus) : base(message, innerException)
{
FailureType = failureType;
CommandStatus = commandStatus;
}
/// <summary>
/// The type of connection failure
/// </summary>
public ConnectionFailureType FailureType { get; }
/// <summary>
/// status of the command while communicating with Redis
/// </summary>
public CommandStatus CommandStatus { get; }
}
/// <summary>
/// Indicates an issue communicating with redis
/// </summary>
#if FEATURE_SERIALIZATION
[Serializable]
#endif
public class RedisException : Exception
{
/// <summary>
/// Deserialization constructor; not intended for general usage
/// </summary>
#if FEATURE_SERIALIZATION
protected RedisException(SerializationInfo info, StreamingContext ctx) : base(info, ctx) { }
#endif
internal RedisException(string message) : base(message) { }
internal RedisException(string message, Exception innerException) : base(message, innerException) { }
}
/// <summary>
/// Indicates an exception raised by a redis server
/// </summary>
#if FEATURE_SERIALIZATION
[Serializable]
#endif
public sealed class RedisServerException : RedisException
{
#if FEATURE_SERIALIZATION
private RedisServerException(SerializationInfo info, StreamingContext ctx) : base(info, ctx) { }
#endif
internal RedisServerException(string message) : base(message) { }
}
sealed class LoggingMessage : Message
{
public readonly TextWriter log;
......
......@@ -1151,7 +1151,7 @@ RawResult TryParseResult(byte[] buffer, ref int offset, ref int count)
partial void DebugEmulateStaleConnection(ref int firstUnansweredWrite);
public void CheckForStaleConnection(ref SocketManager.ManagerState managerState)
public void CheckForStaleConnection(ref SocketManager.ManagerState state)
{
int firstUnansweredWrite = VolatileWrapper.Read(ref firstUnansweredWriteTickCount);
......@@ -1161,7 +1161,7 @@ public void CheckForStaleConnection(ref SocketManager.ManagerState managerState)
if (firstUnansweredWrite != 0 && (now - firstUnansweredWrite) > this.Multiplexer.RawConfig.ResponseTimeout)
{
this.RecordConnectionFailed(ConnectionFailureType.SocketFailure, ref managerState, origin: "CheckForStaleConnection");
this.RecordConnectionFailed(ConnectionFailureType.SocketFailure, ref state, origin: "CheckForStaleConnection");
}
}
}
......
......@@ -93,9 +93,9 @@ public Task<bool> GeoRemoveAsync(RedisKey key, RedisValue member, CommandFlags f
return SortedSetRemoveAsync(key, member, flags);
}
public double? GeoDistance(RedisKey key, RedisValue value0, RedisValue value1, GeoUnit unit = GeoUnit.Meters, CommandFlags flags = CommandFlags.None)
public double? GeoDistance(RedisKey key, RedisValue member1, RedisValue member2, GeoUnit unit = GeoUnit.Meters, CommandFlags flags = CommandFlags.None)
{
var msg = Message.Create(Database, flags, RedisCommand.GEODIST, key, value0, value1, StackExchange.Redis.GeoPosition.GetRedisUnit(unit));
var msg = Message.Create(Database, flags, RedisCommand.GEODIST, key, member1, member2, StackExchange.Redis.GeoPosition.GetRedisUnit(unit));
return ExecuteSync(msg, ResultProcessor.NullableDouble);
}
public Task<double?> GeoDistanceAsync(RedisKey key, RedisValue value0, RedisValue value1, GeoUnit unit = GeoUnit.Meters, CommandFlags flags = CommandFlags.None)
......@@ -1609,9 +1609,9 @@ public Task<long> StringBitOperationAsync(Bitwise operation, RedisKey destinatio
return ExecuteAsync(msg, ResultProcessor.Int64);
}
public long StringBitPosition(RedisKey key, bool value, long start = 0, long end = -1, CommandFlags flags = CommandFlags.None)
public long StringBitPosition(RedisKey key, bool bit, long start = 0, long end = -1, CommandFlags flags = CommandFlags.None)
{
var msg = Message.Create(Database, flags, RedisCommand.BITPOS, key, value, start, end);
var msg = Message.Create(Database, flags, RedisCommand.BITPOS, key, bit, start, end);
return ExecuteSync(msg, ResultProcessor.Int64);
}
......@@ -1783,9 +1783,9 @@ public Task<bool> StringSetAsync(KeyValuePair<RedisKey, RedisValue>[] values, Wh
return ExecuteAsync(msg, ResultProcessor.Boolean);
}
public bool StringSetBit(RedisKey key, long offset, bool value, CommandFlags flags = CommandFlags.None)
public bool StringSetBit(RedisKey key, long offset, bool bit, CommandFlags flags = CommandFlags.None)
{
var msg = Message.Create(Database, flags, RedisCommand.SETBIT, key, offset, value);
var msg = Message.Create(Database, flags, RedisCommand.SETBIT, key, offset, bit);
return ExecuteSync(msg, ResultProcessor.Boolean);
}
......
......@@ -577,14 +577,14 @@ internal override RedisFeatures GetFeatures(int db, RedisKey key, CommandFlags f
return new RedisFeatures(server.Version);
}
public void SlaveOf(EndPoint endpoint, CommandFlags flags = CommandFlags.None)
public void SlaveOf(EndPoint master, CommandFlags flags = CommandFlags.None)
{
if (endpoint == server.EndPoint)
if (master == server.EndPoint)
{
throw new ArgumentException("Cannot slave to self");
}
// prepare the actual slaveof message (not sent yet)
var slaveofMsg = CreateSlaveOfMessage(endpoint, flags);
var slaveofMsg = CreateSlaveOfMessage(master, flags);
var configuration = this.multiplexer.RawConfig;
......@@ -610,10 +610,10 @@ public void SlaveOf(EndPoint endpoint, CommandFlags flags = CommandFlags.None)
}
}
public Task SlaveOfAsync(EndPoint endpoint, CommandFlags flags = CommandFlags.None)
public Task SlaveOfAsync(EndPoint master, CommandFlags flags = CommandFlags.None)
{
var msg = CreateSlaveOfMessage(endpoint, flags);
if (endpoint == server.EndPoint)
var msg = CreateSlaveOfMessage(master, flags);
if (master == server.EndPoint)
{
throw new ArgumentException("Cannot slave to self");
}
......
......@@ -8,7 +8,7 @@
namespace StackExchange.Redis
{
class ScriptParameterMapper
internal static class ScriptParameterMapper
{
public struct ScriptParameters
{
......
......@@ -88,25 +88,25 @@ public override bool Equals(object obj)
/// <summary>
/// Compares two values for equality
/// </summary>
public bool Equals(SortedSetEntry value)
public bool Equals(SortedSetEntry other)
{
return score == value.score && element == value.element;
return score == other.score && element == other.element;
}
/// <summary>
/// Compares two values by score
/// </summary>
public int CompareTo(SortedSetEntry value)
public int CompareTo(SortedSetEntry other)
{
return score.CompareTo(value.score);
return score.CompareTo(other.score);
}
/// <summary>
/// Compares two values by score
/// </summary>
public int CompareTo(object value)
public int CompareTo(object obj)
{
return value is SortedSetEntry ? CompareTo((SortedSetEntry)value) : -1;
return obj is SortedSetEntry ? CompareTo((SortedSetEntry)obj) : -1;
}
/// <summary>
......
namespace StackExchange.Redis
{
class StringSplits
internal static class StringSplits
{
public static readonly char[]
Space = { ' ' },
......
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