Exemplo n.º 1
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;
        }
Exemplo n.º 2
0
 internal RedisChannel(IExecutionPlanner planner,
                       ProcedureCollection procedures,
                       ICommandConnection multiplexedCommander,
                       IConnectionProvider <ISubscriptionConnection> subscribers,
                       IConnectionProvider <ICommandConnection> exclusivePool)
 {
     _multiplexedCommander = multiplexedCommander;
     _exclusivePool        = exclusivePool;
     _subscribers          = subscribers;
     _planner    = planner;
     _procedures = procedures;
     _context    = new ExecutionContext();
 }
Exemplo n.º 3
0
        internal CommandOperation(RESPCommand[] commands, RESPObject[] responses, ProcedureCollection procedures)
        {
            Contract.Assert(commands.Any(), "Creating operation with empty command list.");
            Contract.Assert(responses.Any(), "Creating operation with empty responses lsit.");
            Contract.Assert(procedures != null, "Creating operation with empty procedure list.");
            Contract.Assert(commands.Length == responses.Length, "Commands and responses placeholder have different lenghts.");

            _commands   = commands;
            _responses  = responses;
            _procedures = procedures;

            PointToNextResponse();
        }
Exemplo n.º 4
0
        private static void FormatScriptError(ProcedureCollection procedures, RESPError error)
        {
            var pos = error.Message.IndexOf("Error running script (call to ");

            if (pos != -1 && error.Message.Length >= 72)
            {
                var scriptId = error.Message.Substring(30, 42);
                var sha1     = scriptId.Substring(2);
                ProcedureDefinition script;
                if (procedures.TryGetByDigest(sha1, out script))
                {
                    error.SetMessage(error.Message.Replace(scriptId, String.Format("{0} [sha1: {1}]", script.Name, sha1)));
                }
            }
        }
Exemplo n.º 5
0
        internal static void AmmendScriptErrors(RESPObject[] responses, String[] headers, ProcedureCollection procedures)
        {
            foreach (var item in responses)
            {
                if (item == null || item.Header != RESPHeaders.Error)
                {
                    continue;
                }

                var error = (RESPError)item;
                if (error.Prefix != null && error.Message != null && error.Prefix.Equals("ERR", StringComparison.Ordinal))
                {
                    FormatScriptError(procedures, error);
                }
            }
        }
Exemplo n.º 6
0
 public ProcedureInitializer(ProcedureCollection procedures, IRedisClientLog logger)
 {
     _procedures = procedures;
     _logger     = logger;
 }
Exemplo n.º 7
0
 internal ExecutionPlanner(ProcedureCollection procedures)
 {
     _procedures = procedures;
 }