Commit d6681264 authored by Nick Craver's avatar Nick Craver

Cleanup: RedisServer

parent a6ef7169
......@@ -9,15 +9,13 @@
namespace StackExchange.Redis
{
internal sealed partial class RedisServer : RedisBase, IServer
{
private readonly ServerEndPoint server;
internal RedisServer(ConnectionMultiplexer multiplexer, ServerEndPoint server, object asyncState) : base(multiplexer, asyncState)
{
if (server == null) throw new ArgumentNullException(nameof(server));
this.server = server;
this.server = server ?? throw new ArgumentNullException(nameof(server));
}
public ClusterConfiguration ClusterConfiguration => server.ClusterConfiguration;
......@@ -32,8 +30,8 @@ internal RedisServer(ConnectionMultiplexer multiplexer, ServerEndPoint server, o
public bool AllowSlaveWrites
{
get { return server.AllowSlaveWrites; }
set { server.AllowSlaveWrites = value; }
get => server.AllowSlaveWrites;
set => server.AllowSlaveWrites = value;
}
public ServerType ServerType => server.ServerType;
......@@ -63,9 +61,10 @@ public Task<long> ClientKillAsync(long? id = null, ClientType? clientType = null
var msg = GetClientKillMessage(endpoint, id, clientType, skipMe, flags);
return ExecuteAsync(msg, ResultProcessor.Int64);
}
Message GetClientKillMessage(EndPoint endpoint, long? id, ClientType? clientType, bool skipMe, CommandFlags flags)
private Message GetClientKillMessage(EndPoint endpoint, long? id, ClientType? clientType, bool skipMe, CommandFlags flags)
{
List<RedisValue> parts = new List<RedisValue>(9)
var parts = new List<RedisValue>(9)
{
RedisLiterals.KILL
};
......@@ -194,6 +193,7 @@ public Task ConfigSetAsync(RedisValue setting, RedisValue value, CommandFlags fl
ExecuteSync(Message.Create(-1, flags | CommandFlags.FireAndForget, RedisCommand.CONFIG, RedisLiterals.GET, setting), ResultProcessor.AutoConfigure);
return task;
}
public long DatabaseSize(int database = 0, CommandFlags flags = CommandFlags.None)
{
var msg = Message.Create(database, flags, RedisCommand.DBSIZE);
......@@ -211,6 +211,7 @@ public RedisValue Echo(RedisValue message, CommandFlags flags)
var msg = Message.Create(-1, flags, RedisCommand.ECHO, message);
return ExecuteSync(msg, ResultProcessor.RedisValue);
}
public Task<RedisValue> EchoAsync(RedisValue message, CommandFlags flags)
{
var msg = Message.Create(-1, flags, RedisCommand.ECHO, message);
......@@ -222,6 +223,7 @@ public void FlushAllDatabases(CommandFlags flags = CommandFlags.None)
var msg = Message.Create(-1, flags, RedisCommand.FLUSHALL);
ExecuteSync(msg, ResultProcessor.DemandOK);
}
public Task FlushAllDatabasesAsync(CommandFlags flags = CommandFlags.None)
{
var msg = Message.Create(-1, flags, RedisCommand.FLUSHALL);
......@@ -240,10 +242,7 @@ public Task FlushDatabaseAsync(int database = 0, CommandFlags flags = CommandFla
return ExecuteAsync(msg, ResultProcessor.DemandOK);
}
public ServerCounters GetCounters()
{
return server.GetCounters();
}
public ServerCounters GetCounters() => server.GetCounters();
public IGrouping<string, KeyValuePair<string, string>>[] Info(RedisValue section = default(RedisValue), CommandFlags flags = CommandFlags.None)
{
......@@ -319,6 +318,7 @@ public void MakeMaster(ReplicationChangeOptions options, TextWriter log = null)
{
multiplexer.MakeMaster(server, options, log);
}
public void Save(SaveType type, CommandFlags flags = CommandFlags.None)
{
var msg = GetSaveMessage(type, flags);
......@@ -527,9 +527,7 @@ internal static Message CreateSlaveOfMessage(EndPoint endpoint, CommandFlags fla
}
else
{
string hostRaw;
int portRaw;
if (Format.TryGetHostPort(endpoint, out hostRaw, out portRaw))
if (Format.TryGetHostPort(endpoint, out string hostRaw, out int portRaw))
{
host = hostRaw;
port = portRaw;
......@@ -588,11 +586,10 @@ public void SlaveOf(EndPoint master, CommandFlags flags = CommandFlags.None)
var configuration = this.multiplexer.RawConfig;
// attempt to cease having an opinion on the master; will resume that when replication completes
// (note that this may fail; we aren't depending on it)
if (!string.IsNullOrWhiteSpace(configuration.TieBreaker)
&& this.multiplexer.CommandMap.IsAvailable(RedisCommand.DEL))
&& multiplexer.CommandMap.IsAvailable(RedisCommand.DEL))
{
var del = Message.Create(0, CommandFlags.FireAndForget | CommandFlags.NoRedirect, RedisCommand.DEL, (RedisKey)configuration.TieBreaker);
del.SetInternalCall();
......@@ -601,8 +598,8 @@ public void SlaveOf(EndPoint master, CommandFlags flags = CommandFlags.None)
ExecuteSync(slaveofMsg, ResultProcessor.DemandOK);
// attempt to broadcast a reconfigure message to anybody listening to this server
var channel = this.multiplexer.ConfigurationChangedChannel;
if (channel != null && this.multiplexer.CommandMap.IsAvailable(RedisCommand.PUBLISH))
var channel = multiplexer.ConfigurationChangedChannel;
if (channel != null && multiplexer.CommandMap.IsAvailable(RedisCommand.PUBLISH))
{
var pub = Message.Create(-1, CommandFlags.FireAndForget | CommandFlags.NoRedirect, RedisCommand.PUBLISH, (RedisValue)channel, RedisLiterals.Wildcard);
pub.SetInternalCall();
......@@ -636,7 +633,7 @@ private void FixFlags(Message message, ServerEndPoint server)
}
}
Message GetSaveMessage(SaveType type, CommandFlags flags = CommandFlags.None)
private Message GetSaveMessage(SaveType type, CommandFlags flags = CommandFlags.None)
{
switch(type)
{
......@@ -649,7 +646,7 @@ Message GetSaveMessage(SaveType type, CommandFlags flags = CommandFlags.None)
}
}
ResultProcessor<bool> GetSaveResultProcessor(SaveType type)
private ResultProcessor<bool> GetSaveResultProcessor(SaveType type)
{
switch (type)
{
......@@ -662,15 +659,15 @@ ResultProcessor<bool> GetSaveResultProcessor(SaveType type)
}
}
static class ScriptHash
private static class ScriptHash
{
static readonly byte[] hex = {
private static readonly byte[] hex = {
(byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', (byte)'6', (byte)'7',
(byte)'8', (byte)'9', (byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e', (byte)'f' };
public static RedisValue Encode(byte[] value)
{
if (value == null) return default(RedisValue);
byte[] result = new byte[value.Length * 2];
var result = new byte[value.Length * 2];
int offset = 0;
for (int i = 0; i < value.Length; i++)
{
......@@ -680,6 +677,7 @@ public static RedisValue Encode(byte[] value)
}
return result;
}
public static RedisValue Hash(string value)
{
if (value == null) return default(RedisValue);
......@@ -691,7 +689,7 @@ public static RedisValue Hash(string value)
}
}
sealed class KeysScanEnumerable : CursorEnumerable<RedisKey>
private sealed class KeysScanEnumerable : CursorEnumerable<RedisKey>
{
private readonly RedisValue pattern;
......@@ -726,6 +724,7 @@ protected override Message CreateMessage(long cursor)
}
}
}
protected override ResultProcessor<ScanResult> Processor => processor;
public static readonly ResultProcessor<ScanResult> processor = new KeysResultProcessor();
......
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