public RedisResult <RedisClusterNodeInfo[]> Slaves(RedisParam nodeId) { var result = ExpectBulkString(new RedisCommand(DbIndex, RedisCommandList.Cluster, RedisCommandList.ClusterSlaves)); if (!ReferenceEquals(result, null)) { return(new RedisResult <RedisClusterNodeInfo[]>(RedisClusterNodeInfo.Parse(result))); } return(new RedisResult <RedisClusterNodeInfo[]>(null)); }
protected virtual void DiscoverClusterSlots() { var slotList = (RedisClusterSlotList)null; try { if (!Disposed && m_ServerMode == RedisServerMode.Cluster) { var ep = EndPoint; if (ep != null) { var myIPAndPorts = GetMyIPAndPort(); if (!myIPAndPorts.IsEmpty()) { var bytes = RunSyncTask(new RedisCommand(RedisConstants.UninitializedDbIndex, RedisCommandList.Cluster, RedisCommandType.SendAndReceive, RedisCommandList.ClusterNodes) { Priority = RedisCommandPriority.High }) as RedisBytes; var nodeLines = bytes.ToUTF8String(); if (!nodeLines.IsEmpty()) { var nodes = RedisClusterNodeInfo.Parse(nodeLines); if (!nodes.IsEmpty()) { var node = nodes.FirstOrDefault(n => myIPAndPorts.Contains(n.IpPort)); if (node != null) { var slots = node.Slots; if (!slots.IsEmpty()) { var slotArray = slots.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (!slotArray.IsEmpty()) { slotList = new RedisClusterSlotList(); var length = slotArray.Length; for (var i = 0; i < length; i++) { var slot = slotArray[i]; if (slot != null) { var slotLength = slot.Length; if (slotLength > 0) { var pos = slot.IndexOf('-'); var start = pos > 0 ? slot.Substring(0, pos).ToInt(-1) : 0; var end = pos < slotLength - 1 ? slot.Substring(pos + 1, slotLength - pos - 1).ToInt(-1) : start; if (start > -1) { slotList.Add(new RedisClusterSlot(start, end)); } } } } slotList.Sort(); } } } } } } } } } catch (Exception) { } using (Interlocked.Exchange(ref m_SlotList, slotList)) { } }