示例#1
0
        // 获取指定key对应的主设备节点
        private RedisClient GetRedisClient(string key)
        {
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException("key");
            }

            int slot = CRC16.GetSlot(key);

            if (!_redisClientManagers.ContainsKey(slot))
            {
                throw new SlotNotFoundException(string.Format("No reachable node in cluster for slot {{{0}}}", slot), slot, key);
            }

            var pool = _redisClientManagers[slot];

            return((RedisClient)pool.GetClient());
        }
示例#2
0
 /// <summary>
 /// 根据 key 计算对应的哈希槽
 /// </summary>
 public static int GetSlot(string key)
 {
     key = CRC16.ExtractHashTag(key);
     // optimization with modulo operator with power of 2 equivalent to getCRC16(key) % 16384
     return(GetCRC16(key) & (16384 - 1));
 }