Example #1
0
        internal RedisConnection(IPEndPoint[] endpoints, RedisClientOptions options)
        {
            _loadFactor             = 100;
            _endpoints              = endpoints;
            _options                = options;
            _connectionCancellation = new CancellationTokenSource();
            _requests               = options.QueuesBoundedCapacity.HasValue ? new BlockingCollection <ExecutionToken>(options.QueuesBoundedCapacity.Value) : new BlockingCollection <ExecutionToken>();
            _pending                = new ConcurrentQueue <ExecutionToken>();
            _logger      = _options.Logger;
            _code        = this.GetHashCode().ToString();
            Initializers = new List <IConnectionInitializer>();
            Initializers.Add(new ConnectionInitializer(_options));

            if (options.PingTimeout != Timeout.InfiniteTimeSpan)
            {
                _interval       = TimeSpan.FromMilliseconds(options.PingTimeout.TotalMilliseconds / 2);
                _pingTimer      = new Timer(o => { try { Execute(GeneratePingToken(), CancellationToken.None); } catch (Exception) { } });
                _skipTimerReset = !options.PreventPingIfActive;
            }
            else
            {
                _interval       = Timeout.InfiniteTimeSpan;
                _skipTimerReset = true;
            }
            _logger.Info("Created connection {0} of type {1}.", _code, this.GetType().Name);
        }
Example #2
0
        private RedisClient(RedisClientOptions options)
        {
            _cancel  = new CancellationTokenSource();
            _options = options != null?options.Clone() : RedisClientOptions.Default;

            _logger = _options.Logger;
        }
Example #3
0
        public ConnectionInitializer(RedisClientOptions options)
        {
            if (options == null)
            {
                return;
            }

            _logger   = options.Logger ?? NoLogger.Instance;
            _commands = GenerateCommands(options).ToArray();
        }
Example #4
0
        internal ConnectionPool(Int32 minimum, Int32 maximum, Func <ICommandConnection> factory, IRedisClientLog logger)
        {
            Contract.Assert(minimum >= 0, "Minimum must be bigger or equal than 0");
            Contract.Assert(minimum <= maximum, "Minimum cannot be bigger than Maximum");

            _factory     = factory;
            _queue       = new BlockingCollection <ICommandConnection>(maximum);
            _connections = new ICommandConnection[maximum];
            _current     = minimum;
            _logger      = logger;
            _cancel      = new CancellationTokenSource();

            for (int i = 0; i < minimum; i++)
            {
                var connection = factory();
                _connections[i] = connection;
                _queue.Add(connection);
            }
        }
 public ProcedureInitializer(ProcedureCollection procedures, IRedisClientLog logger)
 {
     _procedures = procedures;
     _logger     = logger;
 }