示例#1
0
        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));
                }
        }
示例#2
0
        /// <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;
        }
示例#3
0
        /// <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 };
        }
示例#4
0
        internal RedisResults(RESPObject[] responses, String[] commandHeaders = null)
        {
            ParameterGuard.CannotBeNull(responses, "responses");

            _responses = responses;
            _results   = new RedisResultInspector[_responses.Length];
        }
示例#5
0
        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;
        }
示例#6
0
        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;
        }
示例#7
0
 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);
     }
 }
示例#8
0
        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);
            }
        }
示例#9
0
 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;
 }
示例#10
0
 internal RedisClientMultipleCommandException(params RedisClientCommandException[] commandExceptions)
     : base("Multiple Redis command failed, please check 'InnerExceptions' property.", new AggregateException(commandExceptions))
 {
     ParameterGuard.CannotBeNullOrEmpty(commandExceptions, "commandExceptions");
     this.InnerExceptions = commandExceptions;
 }
示例#11
0
 private void ValidateMultiplex(MultiplexPoolOptions config)
 {
     ParameterGuard.CannotBeZeroOrNegative(config.CommandConnections, "MultiplexPoolOptions.CommandConnection");
     ParameterGuard.CannotBeZeroOrNegative(config.SubscriptionOptions, "MultiplexPoolOptions.SubscriptionOptions");
 }
示例#12
0
 private void ValidateExclusive(ExclusivePoolOptions config)
 {
     ParameterGuard.CannotBeNegative(config.Minimum, "ExclusivePoolOptions.Minimum");
     ParameterGuard.MustBeBiggerOrEqualThan(config.Maximum, "ExclusivePoolOptions.Maximum", config.Minimum);
 }
示例#13
0
        internal RedisNotification(String header)
        {
            ParameterGuard.CannotBeNullOrEmpty(header, "header");

            this.Header = header;
        }