示例#1
0
        public void ReUsePoolConnection_test()
        {
            var host = "127.0.0.1";
            var port = 6379;

            var connections = new List <RedisConnection>()
            {
                RedisConnectionPool.GetConnection(host, port)
                , RedisConnectionPool.GetConnection(host, port)
                , RedisConnectionPool.GetConnection(host, port)
                , RedisConnectionPool.GetConnection(host, port)
                , RedisConnectionPool.GetConnection(host, port)
                , RedisConnectionPool.GetConnection(host, port)
            };

            foreach (var conn in connections)
            {
                conn.OnConnectionReleased();
            }

            Assert.True(RedisConnectionPool.GetPoolSizeForHost(host, port).Equals(6));

            var newConn = RedisConnectionPool.GetConnection(host, port);

            Assert.True(connections.Any(c => c.Id.Equals(newConn.Id)));
        }
示例#2
0
 public RedisClient(RedisHostInfo hostInfo)
 {
     this.Host     = hostInfo.Host;
     this.Port     = hostInfo.Port;
     this.Password = hostInfo.Password;
     this.Db       = hostInfo.Db;
     _connection   = RedisConnectionPool.GetConnection(this.Host, this.Port, this.Password);
     _connection.Connect();
     _selectDb();
 }
示例#3
0
 public RedisClient(String host, int port = 6379, String password = null, Int32?db = null)
 {
     Host        = host;
     Port        = port;
     Password    = password;
     Db          = db;
     _connection = RedisConnectionPool.GetConnection(host, port, password);
     _connection.Connect();
     _selectDb();
 }
示例#4
0
        public void SteadyStatePoolSize_test()
        {
            var host = "127.0.0.1";
            var port = 6379;

            var connections = new List <RedisConnection>()
            {
                RedisConnectionPool.GetConnection(host, port)
                , RedisConnectionPool.GetConnection(host, port)
                , RedisConnectionPool.GetConnection(host, port)
                , RedisConnectionPool.GetConnection(host, port)
                , RedisConnectionPool.GetConnection(host, port)
                , RedisConnectionPool.GetConnection(host, port)
            };

            Assert.True(RedisConnectionPool.GetPoolSizeForHost(host, port).Equals(6));

            var incrementalConnections = new List <RedisConnection>()
            {
                RedisConnectionPool.GetConnection(host, port)
                , RedisConnectionPool.GetConnection(host, port)
                , RedisConnectionPool.GetConnection(host, port)
            };

            Assert.True(RedisConnectionPool.GetPoolSizeForHost(host, port).Equals(9));

            foreach (var conn in incrementalConnections)
            {
                conn.OnConnectionReleased();
            }

            Assert.True(RedisConnectionPool.GetPoolSizeForHost(host, port).Equals(6));

            foreach (var conn in connections)
            {
                conn.OnConnectionReleased();
            }

            Assert.True(RedisConnectionPool.GetPoolSizeForHost(host, port).Equals(6));
        }
示例#5
0
        public void MaximumPoolSize_test()
        {
            var hostA = "127.0.0.1";
            var hostB = "192.168.1.0";
            var port  = 6379;

            var a_did_throw_exception = false;
            var b_did_throw_exception = false;

            var a_connections = 0;
            var b_connections = 0;

            Action getConnection_A = () => {
                try { var conn = RedisConnectionPool.GetConnection(hostA, port); Interlocked.Increment(ref a_connections); }
                catch (RedisException) { a_did_throw_exception = true; }
            };

            Action getConnection_B = () => {
                try { var conn = RedisConnectionPool.GetConnection(hostB, port); Interlocked.Increment(ref b_connections); }
                catch (RedisException) { b_did_throw_exception = true; }
            };

            List <Task> tasks = new List <Task>();

            for (int x = 0; x < RedisConnectionPool.MAX_POOL_SIZE + 1; x++)
            {
                var t1 = Task.Factory.StartNew(getConnection_A);
                var t2 = Task.Factory.StartNew(getConnection_B);
                tasks.Add(t1); tasks.Add(t2);
            }
            Task.WaitAll(tasks.ToArray());

            Assert.True(a_did_throw_exception);
            Assert.True(b_did_throw_exception);
            Assert.True(a_connections == RedisConnectionPool.MAX_POOL_SIZE);
            Assert.True(b_connections == RedisConnectionPool.MAX_POOL_SIZE);
        }