public IRedisResults Execute <T>(String command, T parameters, CancellationToken cancel) where T : class { ParameterGuard.CannotBeNullOrEmpty(command, "command"); CheckDispose(); var plan = _planner.Build(command); var setup = Pack(plan, parameters); using (var token = new SyncExecutionToken(setup.Item1, setup.Item2)) using (cancel.Register(token.SetCancelled)) { try { Route(plan, token, cancel); token.Wait(cancel); } finally { Clean(); } AmendResults(plan, setup.Item3); return(new RedisResults(setup.Item3, plan.Headers)); } }
/// <summary> /// Initializes a new instance of the <see cref="RedisClient"/> class. /// </summary> /// <param name="endpoints">The Redis endpoints. The selected endpoint is selected in a rota basis.</param> /// <param name="options"><see cref="RedisClientOptions"/></param> public RedisClient(IPEndPoint[] endpoints, RedisClientOptions options = null) : this(options) { ParameterGuard.CannotBeNullOrEmpty(endpoints, "endpoints"); _endpoints = endpoints.ToArray(); _procedures = _options.Procedures != null?_options.Procedures.ToCollection() : ProcedureCollection.Empty; _proceduresInitializer = new ProcedureInitializer(_procedures, _options.Logger); _multiplexedCommander = new AggregatedCommandConnection <RedisCommanderConnection>(_options.MultiplexPool.CommandConnections, CommanderFactory, _options); _subscriptorsPool = new ConnectionSelector <RedisSubscriberConnection>(_options.MultiplexPool.SubscriptionOptions, SubscriberFactory, _options); if (_options.ExclusivePool.Maximum > 0) { _exclusivePool = new ConnectionPool(_options.ExclusivePool.Minimum, _options.ExclusivePool.Maximum, CommanderFactory, _options.Logger); } else { _exclusivePool = DisabledConnectionPool.Instance; } IExecutionPlanner planner = new ExecutionPlanner(_procedures); _planner = _options.UseExecutionPlanCaching ? new CachingExecutionPlanner(planner) : planner; }
/// <summary> /// Initializes a new instance of the <see cref="RedisClient"/> class. /// </summary> /// <param name="endpoint">The Redis endpoint.</param> /// <param name="options"><see cref="RedisClientOptions"/></param> public RedisClient(IPEndPoint endpoint, RedisClientOptions options = null) : this(new[] { endpoint }, options) { ParameterGuard.CannotBeNull(endpoint, "endpoint"); _endpoints = new[] { endpoint }; }
internal RedisResults(RESPObject[] responses, String[] commandHeaders = null) { ParameterGuard.CannotBeNull(responses, "responses"); _responses = responses; _results = new RedisResultInspector[_responses.Length]; }
internal RedisClientCommandException(RESPError error, Int32 lineNumber) : base(String.Format("{0}:'{1}' in line #{2}", error.Prefix, error.Message, lineNumber)) { ParameterGuard.CannotBeZeroOrNegative(lineNumber, "lineNumber"); LineNumber = lineNumber; Prefix = error.Prefix; OriginalMessage = error.Message; }
internal RedisNotification(String header, String subscribedKey, String publishedKey, String content) : this(header) { ParameterGuard.CannotBeNullOrEmpty(subscribedKey, "subscribedKey"); ParameterGuard.CannotBeNullOrEmpty(publishedKey, "publishedKey"); ParameterGuard.CannotBeNullOrEmpty(content, "content"); this.SubscribedKey = subscribedKey; this.PublishedKey = publishedKey; this.Content = content; }
public IRedisResultInspector this[Int32 index] { get { ParameterGuard.IndexMustFitIn(index, "index", _results); IRedisResultInspector result = _results[index]; if (result == null) { result = _results[index] = new RedisResultInspector(_responses[index], index + 1); } return(result); } }
public void Dispatch <T>(String command, T parameters) where T : class { ParameterGuard.CannotBeNullOrEmpty(command, "command"); CheckDispose(); if (_heldConnection == null) { var plan = _planner.Build(command); var setup = Pack(plan, parameters); using (var token = new NoWaitExecutionToken(setup.Item1, setup.Item2)) Route(plan, token, CancellationToken.None); } else { // if in the middle of transaction, it needs to wait // to check if the connection can be cleaned afterwards. Execute <T>(command, parameters, CancellationToken.None); } }
internal RedisClientMultipleCommandException(RESPError error, params RedisClientCommandException[] commandExceptions) : base(String.Format("{0}:'{1}'", error.Prefix, error.Message), new AggregateException(commandExceptions)) { ParameterGuard.CannotBeNullOrEmpty(commandExceptions, "commandExceptions"); this.InnerExceptions = commandExceptions; }
internal RedisClientMultipleCommandException(params RedisClientCommandException[] commandExceptions) : base("Multiple Redis command failed, please check 'InnerExceptions' property.", new AggregateException(commandExceptions)) { ParameterGuard.CannotBeNullOrEmpty(commandExceptions, "commandExceptions"); this.InnerExceptions = commandExceptions; }
private void ValidateMultiplex(MultiplexPoolOptions config) { ParameterGuard.CannotBeZeroOrNegative(config.CommandConnections, "MultiplexPoolOptions.CommandConnection"); ParameterGuard.CannotBeZeroOrNegative(config.SubscriptionOptions, "MultiplexPoolOptions.SubscriptionOptions"); }
private void ValidateExclusive(ExclusivePoolOptions config) { ParameterGuard.CannotBeNegative(config.Minimum, "ExclusivePoolOptions.Minimum"); ParameterGuard.MustBeBiggerOrEqualThan(config.Maximum, "ExclusivePoolOptions.Maximum", config.Minimum); }
internal RedisNotification(String header) { ParameterGuard.CannotBeNullOrEmpty(header, "header"); this.Header = header; }