public bool TryResend(int hashSlot, Message message, EndPoint endpoint, bool isMoved) { try { if (ServerType == ServerType.Standalone || hashSlot < 0 || hashSlot >= RedisClusterSlotCount) { return(false); } ServerEndPoint server = multiplexer.GetServerEndPoint(endpoint); if (server != null) { bool retry = false; if ((message.Flags & CommandFlags.NoRedirect) == 0) { message.SetAsking(!isMoved); message.SetNoRedirect(); // once is enough if (isMoved) { message.SetInternalCall(); } // note that everything so far is talking about MASTER nodes; we might be // wanting a SLAVE, so we'll check ServerEndPoint resendVia = null; var command = message.Command; switch (Message.GetMasterSlaveFlags(message.Flags)) { case CommandFlags.DemandMaster: resendVia = server.IsSelectable(command, isMoved) ? server : null; break; case CommandFlags.PreferMaster: resendVia = server.IsSelectable(command, isMoved) ? server : FindSlave(server, command); break; case CommandFlags.PreferSlave: resendVia = FindSlave(server, command, isMoved) ?? (server.IsSelectable(command, isMoved) ? server : null); break; case CommandFlags.DemandSlave: resendVia = FindSlave(server, command, isMoved); break; } if (resendVia == null) { multiplexer.Trace("Unable to resend to " + endpoint); } else { message.PrepareToResend(resendVia, isMoved); retry = resendVia.TryWrite(message) == WriteResult.Success; } } if (isMoved) // update map; note we can still update the map even if we aren't actually goint to resend { var arr = MapForMutation(); var oldServer = arr[hashSlot]; arr[hashSlot] = server; if (oldServer != server) { multiplexer.OnHashSlotMoved(hashSlot, oldServer?.EndPoint, endpoint); } } return(retry); } return(false); } catch { return(false); } }