Commit 70c9882f authored by Nick Craver's avatar Nick Craver

Cleanup: ServerSelectionStrategy

parent 7e06b342
...@@ -8,7 +8,7 @@ internal sealed class ServerSelectionStrategy ...@@ -8,7 +8,7 @@ internal sealed class ServerSelectionStrategy
{ {
public const int NoSlot = -1, MultipleSlots = -2; public const int NoSlot = -1, MultipleSlots = -2;
private const int RedisClusterSlotCount = 16384; private const int RedisClusterSlotCount = 16384;
static readonly ushort[] crc16tab = private static readonly ushort[] crc16tab =
{ {
0x0000,0x1021,0x2042,0x3063,0x4084,0x50a5,0x60c6,0x70e7, 0x0000,0x1021,0x2042,0x3063,0x4084,0x50a5,0x60c6,0x70e7,
0x8108,0x9129,0xa14a,0xb16b,0xc18c,0xd1ad,0xe1ce,0xf1ef, 0x8108,0x9129,0xa14a,0xb16b,0xc18c,0xd1ad,0xe1ce,0xf1ef,
...@@ -62,6 +62,7 @@ public ServerSelectionStrategy(ConnectionMultiplexer multiplexer) ...@@ -62,6 +62,7 @@ public ServerSelectionStrategy(ConnectionMultiplexer multiplexer)
/// <summary> /// <summary>
/// Computes the hash-slot that would be used by the given key /// Computes the hash-slot that would be used by the given key
/// </summary> /// </summary>
/// <param name="key">The <see cref="RedisKey"/> to determine a slot ID for.</param>
public unsafe int HashSlot(RedisKey key) public unsafe int HashSlot(RedisKey key)
{ {
//HASH_SLOT = CRC16(key) mod 16384 //HASH_SLOT = CRC16(key) mod 16384
...@@ -101,7 +102,6 @@ public ServerEndPoint Select(Message message) ...@@ -101,7 +102,6 @@ public ServerEndPoint Select(Message message)
slot = message.GetHashSlot(this); slot = message.GetHashSlot(this);
if (slot == MultipleSlots) throw ExceptionFactory.MultiSlot(multiplexer.IncludeDetailInExceptions, message); if (slot == MultipleSlots) throw ExceptionFactory.MultiSlot(multiplexer.IncludeDetailInExceptions, message);
break; break;
} }
return Select(slot, message.Command, message.Flags); return Select(slot, message.Command, message.Flags);
} }
...@@ -184,6 +184,7 @@ internal int CombineSlot(int oldSlot, int newSlot) ...@@ -184,6 +184,7 @@ internal int CombineSlot(int oldSlot, int newSlot)
if (oldSlot == NoSlot) return newSlot; if (oldSlot == NoSlot) return newSlot;
return oldSlot == newSlot ? oldSlot : MultipleSlots; return oldSlot == newSlot ? oldSlot : MultipleSlots;
} }
internal int CombineSlot(int oldSlot, RedisKey key) internal int CombineSlot(int oldSlot, RedisKey key)
{ {
if (oldSlot == MultipleSlots || key.IsNull) return oldSlot; if (oldSlot == MultipleSlots || key.IsNull) return oldSlot;
...@@ -192,6 +193,7 @@ internal int CombineSlot(int oldSlot, RedisKey key) ...@@ -192,6 +193,7 @@ internal int CombineSlot(int oldSlot, RedisKey key)
if (oldSlot == NoSlot) return newSlot; if (oldSlot == NoSlot) return newSlot;
return oldSlot == newSlot ? oldSlot : MultipleSlots; return oldSlot == newSlot ? oldSlot : MultipleSlots;
} }
internal int CountCoveredSlots() internal int CountCoveredSlots()
{ {
var arr = map; var arr = map;
...@@ -211,7 +213,7 @@ internal void UpdateClusterRange(int fromInclusive, int toInclusive, ServerEndPo ...@@ -211,7 +213,7 @@ internal void UpdateClusterRange(int fromInclusive, int toInclusive, ServerEndPo
} }
} }
static unsafe int IndexOf(byte* ptr, byte value, int start, int end) private static unsafe int IndexOf(byte* ptr, byte value, int start, int end)
{ {
for (int offset = start; offset < end; offset++) for (int offset = start; offset < end; offset++)
if (ptr[offset] == value) return offset; if (ptr[offset] == value) return offset;
......
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