Commit 0be88ee3 authored by Nick Craver's avatar Nick Craver

Cleanup: ServerSelectionStrategery

parent 0acb02ab
...@@ -49,14 +49,12 @@ internal sealed class ServerSelectionStrategy ...@@ -49,14 +49,12 @@ internal sealed class ServerSelectionStrategy
private ServerEndPoint[] map; private ServerEndPoint[] map;
private ServerType serverType = ServerType.Standalone;
public ServerSelectionStrategy(ConnectionMultiplexer multiplexer) public ServerSelectionStrategy(ConnectionMultiplexer multiplexer)
{ {
this.multiplexer = multiplexer; this.multiplexer = multiplexer;
} }
public ServerType ServerType { get { return serverType; } set { serverType = value; } } public ServerType ServerType { get; set; } = ServerType.Standalone;
internal int TotalSlots => RedisClusterSlotCount; internal int TotalSlots => RedisClusterSlotCount;
/// <summary> /// <summary>
...@@ -93,7 +91,7 @@ public ServerEndPoint Select(Message message) ...@@ -93,7 +91,7 @@ public ServerEndPoint Select(Message message)
{ {
if (message == null) throw new ArgumentNullException(nameof(message)); if (message == null) throw new ArgumentNullException(nameof(message));
int slot = NoSlot; int slot = NoSlot;
switch (serverType) switch (ServerType)
{ {
case ServerType.Cluster: case ServerType.Cluster:
case ServerType.Twemproxy: // strictly speaking twemproxy uses a different hashing algo, but the hash-tag behavior is case ServerType.Twemproxy: // strictly speaking twemproxy uses a different hashing algo, but the hash-tag behavior is
...@@ -108,7 +106,7 @@ public ServerEndPoint Select(Message message) ...@@ -108,7 +106,7 @@ public ServerEndPoint Select(Message message)
public ServerEndPoint Select(int db, RedisCommand command, RedisKey key, CommandFlags flags) public ServerEndPoint Select(int db, RedisCommand command, RedisKey key, CommandFlags flags)
{ {
int slot = serverType == ServerType.Cluster ? HashSlot(key) : NoSlot; int slot = ServerType == ServerType.Cluster ? HashSlot(key) : NoSlot;
return Select(slot, command, flags); return Select(slot, command, flags);
} }
...@@ -116,7 +114,7 @@ public bool TryResend(int hashSlot, Message message, EndPoint endpoint, bool isM ...@@ -116,7 +114,7 @@ public bool TryResend(int hashSlot, Message message, EndPoint endpoint, bool isM
{ {
try try
{ {
if (serverType == ServerType.Standalone || hashSlot < 0 || hashSlot >= RedisClusterSlotCount) return false; if (ServerType == ServerType.Standalone || hashSlot < 0 || hashSlot >= RedisClusterSlotCount) return false;
ServerEndPoint server = multiplexer.GetServerEndPoint(endpoint); ServerEndPoint server = multiplexer.GetServerEndPoint(endpoint);
if (server != null) if (server != null)
...@@ -222,7 +220,7 @@ private static unsafe int IndexOf(byte* ptr, byte value, int start, int end) ...@@ -222,7 +220,7 @@ private static unsafe int IndexOf(byte* ptr, byte value, int start, int end)
private ServerEndPoint Any(RedisCommand command, CommandFlags flags) private ServerEndPoint Any(RedisCommand command, CommandFlags flags)
{ {
return multiplexer.AnyConnected(serverType, (uint)Interlocked.Increment(ref anyStartOffset), command, flags); return multiplexer.AnyConnected(ServerType, (uint)Interlocked.Increment(ref anyStartOffset), command, flags);
} }
private ServerEndPoint FindMaster(ServerEndPoint endpoint, RedisCommand command) private ServerEndPoint FindMaster(ServerEndPoint endpoint, RedisCommand command)
......
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