Commit 43c1df00 authored by Nick Craver's avatar Nick Craver

General zero-functionality-change cleanup

parent b65bb3e3
......@@ -47,9 +47,9 @@ protected override Job Configure(Job j)
[Config(typeof(CustomConfig))]
public class RedisBenchmarks : IDisposable
{
SocketManager mgr;
ConnectionMultiplexer connection;
IDatabase db;
private SocketManager mgr;
private ConnectionMultiplexer connection;
private IDatabase db;
/// <summary>
/// Create
......@@ -64,7 +64,7 @@ public RedisBenchmarks()
db.GeoAdd(GeoKey, 13.361389, 38.115556, "Palermo ");
db.GeoAdd(GeoKey, 15.087269, 37.502669, "Catania");
}
static readonly RedisKey GeoKey = "GeoTest", IncrByKey = "counter";
private static readonly RedisKey GeoKey = "GeoTest", IncrByKey = "counter";
void IDisposable.Dispose()
{
mgr?.Dispose();
......@@ -87,7 +87,7 @@ void IDisposable.Dispose()
public int ExecuteIncrBy()
{
var rand = new Random(12345);
db.KeyDelete(IncrByKey, CommandFlags.FireAndForget);
int expected = 0;
for (int i = 0; i < COUNT; i++)
......@@ -168,7 +168,6 @@ public async Task<int> ExecuteGeoRadiusAsync()
}
#pragma warning disable CS1591
[Config(typeof(SlowConfig))]
public class Issue898 : IDisposable
{
......@@ -182,8 +181,7 @@ public Issue898()
db = mux.GetDatabase();
}
const int max = 100000;
private const int max = 100000;
[Benchmark(OperationsPerInvoke = max)]
public void Load()
{
......@@ -202,7 +200,7 @@ public async Task LoadAsync()
}
[Benchmark(OperationsPerInvoke = max)]
public void Sample()
{
{
var rnd = new Random();
for (int i = 0; i < max; ++i)
......
......@@ -6,7 +6,7 @@
namespace KestrelRedisServer
{
public class Program
public static class Program
{
public static void Main(string[] args)
{
......
......@@ -9,7 +9,7 @@ namespace KestrelRedisServer
{
public class Startup : IDisposable
{
RespServer _server = new MemoryCacheRedisServer();
private readonly RespServer _server = new MemoryCacheRedisServer();
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
......
......@@ -8,6 +8,8 @@
<Rules AnalyzerId="Roslynator.CSharp.Analyzers" RuleNamespace="Roslynator.CSharp.Analyzers">
<Rule Id="RCS1047" Action="None" />
<Rule Id="RCS1057" Action="None" />
<Rule Id="RCS1146" Action="None" />
<Rule Id="RCS1154" Action="None" />
<Rule Id="RCS1191" Action="None" />
</Rules>
</RuleSet>
\ No newline at end of file
......@@ -67,7 +67,7 @@ protected override bool Srem(int database, RedisKey key, RedisValue value)
protected override long Scard(int database, RedisKey key)
=> GetSet(key, false)?.Count ?? 0;
HashSet<RedisValue> GetSet(RedisKey key, bool create)
private HashSet<RedisValue> GetSet(RedisKey key, bool create)
{
var set = (HashSet<RedisValue>)_cache[key];
if (set == null && create)
......@@ -109,8 +109,8 @@ protected override long Llen(int database, RedisKey key)
=> GetStack(key, false)?.Count ?? 0;
[MethodImpl(MethodImplOptions.NoInlining)]
static void ThrowArgumentOutOfRangeException() => throw new ArgumentOutOfRangeException();
private static void ThrowArgumentOutOfRangeException() => throw new ArgumentOutOfRangeException();
protected override void LRange(int database, RedisKey key, long start, Span<TypedRedisValue> arr)
{
var stack = GetStack(key, false);
......@@ -129,7 +129,7 @@ protected override void LRange(int database, RedisKey key, long start, Span<Type
}
}
Stack<RedisValue> GetStack(RedisKey key, bool create)
private Stack<RedisValue> GetStack(RedisKey key, bool create)
{
var stack = (Stack<RedisValue>)_cache[key];
if (stack == null && create)
......@@ -139,7 +139,5 @@ Stack<RedisValue> GetStack(RedisKey key, bool create)
}
return stack;
}
}
}
......@@ -11,7 +11,7 @@ namespace StackExchange.Redis.Server
public int Count { get; }
public override string ToString() => Count == 0 ? "(n/a)" : GetString(0).ToString();
public override string ToString() => Count == 0 ? "(n/a)" : GetString(0);
public override bool Equals(object obj) => throw new NotSupportedException();
public TypedRedisValue WrongArgCount() => TypedRedisValue.Error($"ERR wrong number of arguments for '{ToString()}' command");
......@@ -19,7 +19,6 @@ namespace StackExchange.Redis.Server
public TypedRedisValue CommandNotFound()
=> TypedRedisValue.Error($"ERR unknown command '{ToString()}'");
public TypedRedisValue UnknownSubcommandOrArgumentCount() => TypedRedisValue.Error($"ERR Unknown subcommand or wrong number of arguments for '{ToString()}'.");
public string GetString(int index)
......
......@@ -502,10 +502,10 @@ private TypedRedisValue SubscribeImpl(RedisClient client, RedisRequest request)
}
return reply;
}
static readonly CommandBytes
private static readonly CommandBytes
s_Subscribe = new CommandBytes("subscribe"),
s_Unsubscribe = new CommandBytes("unsubscribe");
static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
private static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
[RedisCommand(1, LockFree = true)]
protected virtual TypedRedisValue Time(RedisClient client, RedisRequest request)
......@@ -542,6 +542,5 @@ protected virtual long IncrBy(int database, RedisKey key, long delta)
Set(database, key, value);
return value;
}
}
}
......@@ -23,7 +23,7 @@ public enum ShutdownReason
private readonly List<RedisClient> _clients = new List<RedisClient>();
private readonly TextWriter _output;
public RespServer(TextWriter output = null)
protected RespServer(TextWriter output = null)
{
_output = output;
_commands = BuildCommands(this);
......@@ -96,7 +96,7 @@ protected sealed class RedisCommandAttribute : Attribute
}
private readonly Dictionary<CommandBytes, RespCommand> _commands;
readonly struct RespCommand
private readonly struct RespCommand
{
public RespCommand(RedisCommandAttribute attrib, MethodInfo method, RespServer server)
{
......@@ -109,14 +109,14 @@ public RespCommand(RedisCommandAttribute attrib, MethodInfo method, RespServer s
LockFree = attrib.LockFree;
_subcommands = null;
}
CommandBytes CommandBytes { get; }
private CommandBytes CommandBytes { get; }
public string Command { get; }
public string SubCommand { get; }
public bool IsSubCommand => !string.IsNullOrEmpty(SubCommand);
public int Arity { get; }
public int MaxArgs { get; }
public bool LockFree { get; }
readonly RespOperation _operation;
private readonly RespOperation _operation;
private readonly RespCommand[] _subcommands;
public bool HasSubCommands => _subcommands != null;
......@@ -182,7 +182,7 @@ internal int NetArity()
}
}
delegate TypedRedisValue RespOperation(RedisClient client, RedisRequest request);
private delegate TypedRedisValue RespOperation(RedisClient client, RedisRequest request);
// for extensibility, so that a subclass can get their own client type
// to be used via ListenForConnections
......
......@@ -11,7 +11,7 @@ public sealed class RespSocketServer : SocketServer
public RespSocketServer(RespServer server)
{
_server = server ?? throw new ArgumentNullException(nameof(server));
server.Shutdown.ContinueWith((t, o) => ((SocketServer)o).Dispose(), this);
server.Shutdown.ContinueWith((_, o) => ((SocketServer)o).Dispose(), this);
}
protected override void OnStarted(EndPoint endPoint)
=> _server.Log("Server is listening on " + endPoint);
......
......@@ -341,7 +341,6 @@ public void SSLParseViaConfig_Issue883_ConfigObject()
}
public static RemoteCertificateValidationCallback ShowCertFailures(TextWriterOutputHelper output) {
if (output == null) return null;
return (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) =>
......@@ -383,7 +382,6 @@ void WriteStatus(X509ChainStatus[] status)
return sslPolicyErrors == SslPolicyErrors.None;
};
}
[Fact]
public void SSLParseViaConfig_Issue883_ConfigString()
......
......@@ -79,7 +79,7 @@ internal ChannelMessageQueue(RedisChannel redisChannel, RedisSubscriber parent)
_parent = parent;
_queue = System.Threading.Channels.Channel.CreateUnbounded<ChannelMessage>(s_ChannelOptions);
_queue.Reader.Completion.ContinueWith(
(t, state) => ((ChannelMessageQueue)state).IsCompleted = true, this, TaskContinuationOptions.ExecuteSynchronously);
(_, state) => ((ChannelMessageQueue)state).IsCompleted = true, this, TaskContinuationOptions.ExecuteSynchronously);
}
private static readonly UnboundedChannelOptions s_ChannelOptions = new UnboundedChannelOptions
{
......
......@@ -40,14 +40,14 @@ internal unsafe static CommandBytes TrimToFit(string value)
public override int GetHashCode()
{
var hashCode = -1923861349;
hashCode = hashCode * -1521134295 + _0.GetHashCode();
hashCode = hashCode * -1521134295 + _1.GetHashCode();
hashCode = hashCode * -1521134295 + _2.GetHashCode();
hashCode = (hashCode * -1521134295) + _0.GetHashCode();
hashCode = (hashCode * -1521134295) + _1.GetHashCode();
hashCode = (hashCode * -1521134295) + _2.GetHashCode();
return hashCode;
}
public override bool Equals(object obj) => obj is CommandBytes cb && Equals(cb);
public bool Equals(CommandBytes value) => _0 == value._0 && _1 == value._1 && _2 == value._2;
public bool Equals(CommandBytes other) => _0 == other._0 && _1 == other._1 && _2 == other._2;
// note: don't add == operators; with the implicit op above, that invalidates "==null" compiler checks (which should report a failure!)
......@@ -182,7 +182,7 @@ private static unsafe int LowerCasifyUnicode(int oldLen, byte* bPtr)
return newLen;
}
static byte ToLowerInvariantAscii(byte b) => b >= 'A' && b <= 'Z' ? (byte)(b | 32) : b;
private static byte ToLowerInvariantAscii(byte b) => b >= 'A' && b <= 'Z' ? (byte)(b | 32) : b;
internal unsafe byte[] ToArray()
{
......
......@@ -25,7 +25,7 @@ internal static Exception CommandDisabled(string command)
=> new RedisCommandException("This operation has been disabled in the command-map and cannot be used: " + command);
internal static Exception TooManyArgs(string command, int argCount)
=> new RedisCommandException($"This operation would involve too many arguments ({(argCount + 1)} vs the redis limit of {PhysicalConnection.REDIS_MAX_ARGS}): {command}");
=> new RedisCommandException($"This operation would involve too many arguments ({argCount + 1} vs the redis limit of {PhysicalConnection.REDIS_MAX_ARGS}): {command}");
internal static Exception ConnectionFailure(bool includeDetail, ConnectionFailureType failureType, string message, ServerEndPoint server)
{
......
......@@ -26,7 +26,6 @@ internal sealed partial class PhysicalConnection : IDisposable
private const int DefaultRedisDatabaseCount = 16;
//private static readonly AsyncCallback endRead = result =>
//{
// PhysicalConnection physical;
......@@ -608,12 +607,11 @@ internal static void WriteBulkString(RedisValue value, PipeWriter output)
internal const int REDIS_MAX_ARGS = 1024 * 1024; // there is a <= 1024*1024 max constraint inside redis itself: https://github.com/antirez/redis/blob/6c60526db91e23fb2d666fc52facc9a11780a2a3/src/networking.c#L1024
internal void WriteHeader(RedisCommand command, int arguments, CommandBytes commandBytes = default)
{
var bridge = BridgeCouldBeNull;
if (bridge == null) throw new ObjectDisposedException(physicalName);
if (command == RedisCommand.UNKNOWN)
{
// using >= here because we will be adding 1 for the command itself (which is an arg for the purposes of the multi-bulk protocol)
......@@ -929,7 +927,7 @@ internal static void WriteUnifiedPrefixedString(PipeWriter writer, byte[] prefix
}
[ThreadStatic]
static Encoder s_PerThreadEncoder;
private static Encoder s_PerThreadEncoder;
internal static Encoder GetPerThreadEncoder()
{
var encoder = s_PerThreadEncoder;
......@@ -996,7 +994,7 @@ unsafe static internal void WriteRaw(PipeWriter writer, string value, int expect
if (totalBytes != expectedLength) throw new InvalidOperationException("String encode length check failure");
}
}
private static void WriteUnifiedPrefixedBlob(PipeWriter writer, byte[] prefix, byte[] value)
{
// ${total-len}\r\n
......
......@@ -200,7 +200,7 @@ internal bool IsEqual(CommandBytes expected)
if (expected.Length != _payload.Length) return false;
return new CommandBytes(_payload).Equals(expected);
}
internal unsafe bool IsEqual(byte[] expected)
{
if (expected == null) throw new ArgumentNullException(nameof(expected));
......
......@@ -96,7 +96,6 @@ public static readonly RedisValue
REMOVE = "REMOVE",
// SET = "SET",
MinusSymbol = "-",
PlusSumbol = "+",
Wildcard = "*",
......
......@@ -89,7 +89,7 @@ internal static RedisResult TryCreate(PhysicalConnection connection, RawResult r
/// Indicates whether this result was a null result
/// </summary>
public abstract bool IsNull { get; }
/// <summary>
/// Interprets the result as a <see cref="string"/>.
/// </summary>
......
......@@ -38,7 +38,7 @@ internal RedisValue(object obj, long val)
private readonly static object Sentinel_Integer = new object();
private readonly static object Sentinel_Raw = new object();
private readonly static object Sentinel_Double = new object();
/// <summary>
/// Obtain this value as an object - to be used alongside Unbox
/// </summary>
......
......@@ -4,16 +4,16 @@
using System.Threading.Tasks;
using StackExchange.Redis;
static class Program
internal static class Program
{
static void Main()
private static void Main()
{
using (var muxer = ConnectionMultiplexer.Connect("localhost:6379", Console.Out))
{
muxer.GetDatabase().Ping();
}
}
static async Task Main2()
private static async Task Main2()
{
const int ClientCount = 150, ConnectionCount = 10;
CancellationTokenSource cancel = new CancellationTokenSource();
......@@ -53,9 +53,9 @@ static async Task Main2()
}
}
static int clients;
static long totalPings, pings, lastTicks;
static async Task ShowState(CancellationToken cancellation)
private static int clients;
private static long totalPings, pings, lastTicks;
private static async Task ShowState(CancellationToken cancellation)
{
while (!cancellation.IsCancellationRequested)
{
......@@ -80,7 +80,7 @@ private static string Rate(long pingsInInterval, long deltaTicks)
return (pingsInInterval / seconds).ToString("0.0");
}
static async Task RunClient(RedisKey key, int seed, IDatabase db, CancellationToken cancellation)
private static async Task RunClient(RedisKey key, int seed, IDatabase db, CancellationToken cancellation)
{
Interlocked.Increment(ref clients);
try
......
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