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() ...@@ -254,7 +254,8 @@ public void GetInfo()
var info2 = server.Info("cpu"); var info2 = server.Info("cpu");
Assert.Single(info2); Assert.Single(info2);
var cpu = info2.Single(); var cpu = info2.Single();
Assert.True(cpu.Count() > 2); var cpuCount = cpu.Count();
Assert.True(cpuCount > 2);
Assert.Equal("CPU", cpu.Key); Assert.Equal("CPU", cpu.Key);
Assert.Contains(cpu, x => x.Key == "used_cpu_sys"); Assert.Contains(cpu, x => x.Key == "used_cpu_sys");
Assert.Contains(cpu, x => x.Key == "used_cpu_user"); Assert.Contains(cpu, x => x.Key == "used_cpu_user");
......
...@@ -112,9 +112,9 @@ public override bool Equals(object obj) ...@@ -112,9 +112,9 @@ public override bool Equals(object obj)
/// <summary> /// <summary>
/// Indicates whether two ranges are equal /// Indicates whether two ranges are equal
/// </summary> /// </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> /// <summary>
...@@ -456,11 +456,11 @@ public override bool Equals(object obj) ...@@ -456,11 +456,11 @@ public override bool Equals(object obj)
/// <summary> /// <summary>
/// Indicates whether two ClusterNode instances are equivalent /// Indicates whether two ClusterNode instances are equivalent
/// </summary> /// </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> /// <summary>
......
...@@ -285,8 +285,8 @@ public enum CompletionType ...@@ -285,8 +285,8 @@ public enum CompletionType
/// </summary> /// </summary>
Async = 2 Async = 2
} }
#if FEATURE_PERFCOUNTER
#if FEATURE_PERFCOUNTER
internal static class PerfCounterHelper internal static class PerfCounterHelper
{ {
private static readonly object staticLock = new object(); private static readonly object staticLock = new object();
...@@ -334,7 +334,7 @@ public static bool TryGetSystemCPU(out float value) ...@@ -334,7 +334,7 @@ public static bool TryGetSystemCPU(out float value)
} }
#endif #endif
#if FEATURE_THREADPOOL #if FEATURE_THREADPOOL
internal class CompletionTypeHelper internal static class CompletionTypeHelper
{ {
public static void RunWithCompletionType(Func<AsyncCallback, IAsyncResult> beginAsync, AsyncCallback callback, CompletionType completionType) 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) ...@@ -139,9 +139,9 @@ public override bool Equals(object obj)
/// <summary> /// <summary>
/// Compares two values for equality /// Compares two values for equality
/// </summary> /// </summary>
public bool Equals(GeoPosition value) public bool Equals(GeoPosition other)
{ {
return this == value; return this == other;
} }
/// <summary> /// <summary>
/// Compares two values for equality /// Compares two values for equality
...@@ -220,9 +220,9 @@ public override bool Equals(object obj) ...@@ -220,9 +220,9 @@ public override bool Equals(object obj)
/// <summary> /// <summary>
/// Compares two values for equality /// Compares two values for equality
/// </summary> /// </summary>
public bool Equals(GeoEntry value) public bool Equals(GeoEntry other)
{ {
return this == value; return this == other;
} }
/// <summary> /// <summary>
/// Compares two values for equality /// Compares two values for equality
......
...@@ -76,9 +76,9 @@ public override bool Equals(object obj) ...@@ -76,9 +76,9 @@ public override bool Equals(object obj)
/// <summary> /// <summary>
/// Compares two values for equality /// Compares two values for equality
/// </summary> /// </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> /// <summary>
/// Compares two values for equality /// Compares two values for equality
......
...@@ -32,13 +32,13 @@ public bool GeoAdd(RedisKey key, double longitude, double latitude, RedisValue m ...@@ -32,13 +32,13 @@ public bool GeoAdd(RedisKey key, double longitude, double latitude, RedisValue m
return Inner.GeoAdd(ToInner(key), longitude, latitude, member, flags); 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) 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 ...@@ -46,9 +46,9 @@ public bool GeoRemove(RedisKey key, RedisValue member, CommandFlags flags = Comm
return Inner.GeoRemove(ToInner(key), member, flags); 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) public string[] GeoHash(RedisKey key, RedisValue[] members, CommandFlags flags = CommandFlags.None)
......
...@@ -2,149 +2,12 @@ ...@@ -2,149 +2,12 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
#if FEATURE_SERIALIZATION
using System.Runtime.Serialization;
#endif
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace StackExchange.Redis 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 sealed class LoggingMessage : Message
{ {
public readonly TextWriter log; public readonly TextWriter log;
......
...@@ -1151,7 +1151,7 @@ RawResult TryParseResult(byte[] buffer, ref int offset, ref int count) ...@@ -1151,7 +1151,7 @@ RawResult TryParseResult(byte[] buffer, ref int offset, ref int count)
partial void DebugEmulateStaleConnection(ref int firstUnansweredWrite); 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); int firstUnansweredWrite = VolatileWrapper.Read(ref firstUnansweredWriteTickCount);
...@@ -1161,7 +1161,7 @@ public void CheckForStaleConnection(ref SocketManager.ManagerState managerState) ...@@ -1161,7 +1161,7 @@ public void CheckForStaleConnection(ref SocketManager.ManagerState managerState)
if (firstUnansweredWrite != 0 && (now - firstUnansweredWrite) > this.Multiplexer.RawConfig.ResponseTimeout) 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 ...@@ -93,9 +93,9 @@ public Task<bool> GeoRemoveAsync(RedisKey key, RedisValue member, CommandFlags f
return SortedSetRemoveAsync(key, member, flags); 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); return ExecuteSync(msg, ResultProcessor.NullableDouble);
} }
public Task<double?> GeoDistanceAsync(RedisKey key, RedisValue value0, RedisValue value1, GeoUnit unit = GeoUnit.Meters, CommandFlags flags = CommandFlags.None) 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 ...@@ -1609,9 +1609,9 @@ public Task<long> StringBitOperationAsync(Bitwise operation, RedisKey destinatio
return ExecuteAsync(msg, ResultProcessor.Int64); 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); return ExecuteSync(msg, ResultProcessor.Int64);
} }
...@@ -1783,9 +1783,9 @@ public Task<bool> StringSetAsync(KeyValuePair<RedisKey, RedisValue>[] values, Wh ...@@ -1783,9 +1783,9 @@ public Task<bool> StringSetAsync(KeyValuePair<RedisKey, RedisValue>[] values, Wh
return ExecuteAsync(msg, ResultProcessor.Boolean); 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); return ExecuteSync(msg, ResultProcessor.Boolean);
} }
......
...@@ -577,14 +577,14 @@ internal override RedisFeatures GetFeatures(int db, RedisKey key, CommandFlags f ...@@ -577,14 +577,14 @@ internal override RedisFeatures GetFeatures(int db, RedisKey key, CommandFlags f
return new RedisFeatures(server.Version); 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"); throw new ArgumentException("Cannot slave to self");
} }
// prepare the actual slaveof message (not sent yet) // prepare the actual slaveof message (not sent yet)
var slaveofMsg = CreateSlaveOfMessage(endpoint, flags); var slaveofMsg = CreateSlaveOfMessage(master, flags);
var configuration = this.multiplexer.RawConfig; var configuration = this.multiplexer.RawConfig;
...@@ -610,10 +610,10 @@ public void SlaveOf(EndPoint endpoint, CommandFlags flags = CommandFlags.None) ...@@ -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); var msg = CreateSlaveOfMessage(master, flags);
if (endpoint == server.EndPoint) if (master == server.EndPoint)
{ {
throw new ArgumentException("Cannot slave to self"); throw new ArgumentException("Cannot slave to self");
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
namespace StackExchange.Redis namespace StackExchange.Redis
{ {
class ScriptParameterMapper internal static class ScriptParameterMapper
{ {
public struct ScriptParameters public struct ScriptParameters
{ {
......
...@@ -88,25 +88,25 @@ public override bool Equals(object obj) ...@@ -88,25 +88,25 @@ public override bool Equals(object obj)
/// <summary> /// <summary>
/// Compares two values for equality /// Compares two values for equality
/// </summary> /// </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> /// <summary>
/// Compares two values by score /// Compares two values by score
/// </summary> /// </summary>
public int CompareTo(SortedSetEntry value) public int CompareTo(SortedSetEntry other)
{ {
return score.CompareTo(value.score); return score.CompareTo(other.score);
} }
/// <summary> /// <summary>
/// Compares two values by score /// Compares two values by score
/// </summary> /// </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> /// <summary>
......
namespace StackExchange.Redis namespace StackExchange.Redis
{ {
class StringSplits internal static class StringSplits
{ {
public static readonly char[] public static readonly char[]
Space = { ' ' }, 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