public async Task<IRedisResponse> SendAsync(IClusterCommand command, MasterSlavePreference masterSlavePreference) { var slot = command.GetSlot(); var movedKeyRetriesLeft = _configuration.MaximumMovedKeyRetries; while (movedKeyRetriesLeft > 0) { var nodeForThisSlot = _nodes.GetBySlot(slot); if (nodeForThisSlot == null) { //TODO: Reload cluster/slot info throw ExceptionBecause.Cluster.CouldNotFindSlotOwner(slot); } var result = await nodeForThisSlot.SendAsync(command, masterSlavePreference); if (result.Value.IsError) { var movedResponse = MovedResponse.From(result); if (movedResponse != null) { await _nodes.UpdateSlotOwnership(movedResponse); movedKeyRetriesLeft--; continue; } } return result; } throw ExceptionBecause.Cluster.RetriedMovedKeyUntilLimitReached(slot, movedKeyRetriesLeft); }
public async Task<IRedisResponse> SendAsync(ICommand command, MasterSlavePreference masterSlavePreference) { IConnectionPool connectionPool; switch (masterSlavePreference) { case MasterSlavePreference.Either: { var robin = _roundRobin++ % (_slaveConnectionPools.Length + 1); connectionPool = robin == 0 ? _masterConnectionPool : _slaveConnectionPools[robin - 1]; break; } case MasterSlavePreference.MasterOnly: { connectionPool = _masterConnectionPool; break; } case MasterSlavePreference.SlaveOnly: { if (_slaveConnectionPools.Length == 0) throw ExceptionBecause.Node.DoesNotHaveSlave(); var robin = _roundRobin++ % _slaveConnectionPools.Length; connectionPool = _slaveConnectionPools[robin]; break; } default: //case MasterSlavePreference.SlaveIfPresent: { if (_slaveConnectionPools.Length == 0) { connectionPool = _masterConnectionPool; } else { var robin = _roundRobin++ % _slaveConnectionPools.Length; connectionPool = _slaveConnectionPools[robin]; } break; } } return await connectionPool.SendAsync(command); }
public async Task<IRedisResponse> SendAsync(IClusterCommand clusterCommand, MasterSlavePreference masterSlavePreference) { return await _node.SendAsync(clusterCommand.ToCommand(), masterSlavePreference); }