예제 #1
0
        public async Task Can_have_different_pool_size_and_host_configurations()
        {
            var writeHosts = new[] { "readwrite1" };
            var readHosts  = new[] { "read1", "read2" };

            const int poolSizeMultiplier = 4;

            await using IRedisClientsManagerAsync manager = new PooledRedisClientManager(writeHosts, readHosts,
                                                                                         new RedisClientManagerConfig
            {
                MaxWritePoolSize = writeHosts.Length * poolSizeMultiplier,
                MaxReadPoolSize  = readHosts.Length * poolSizeMultiplier,
                AutoStart        = true,
            }
                                                                                         );
            //A poolsize of 4 will not block getting 4 clients
            await using (var client1 = await manager.GetClientAsync())
                await using (var client2 = await manager.GetClientAsync())
                    await using (var client3 = await manager.GetClientAsync())
                        await using (var client4 = await manager.GetClientAsync())
                        {
                            AssertClientHasHost(client1, writeHosts[0]);
                            AssertClientHasHost(client2, writeHosts[0]);
                            AssertClientHasHost(client3, writeHosts[0]);
                            AssertClientHasHost(client4, writeHosts[0]);
                        }

            //A poolsize of 8 will not block getting 8 clients
            await using (var client1 = await manager.GetReadOnlyClientAsync())
                await using (var client2 = await manager.GetReadOnlyClientAsync())
                    await using (var client3 = await manager.GetReadOnlyClientAsync())
                        await using (var client4 = await manager.GetReadOnlyClientAsync())
                            await using (var client5 = await manager.GetReadOnlyClientAsync())
                                await using (var client6 = await manager.GetReadOnlyClientAsync())
                                    await using (var client7 = await manager.GetReadOnlyClientAsync())
                                        await using (var client8 = await manager.GetReadOnlyClientAsync())
                                        {
                                            AssertClientHasHost(client1, readHosts[0]);
                                            AssertClientHasHost(client2, readHosts[1]);
                                            AssertClientHasHost(client3, readHosts[0]);
                                            AssertClientHasHost(client4, readHosts[1]);
                                            AssertClientHasHost(client5, readHosts[0]);
                                            AssertClientHasHost(client6, readHosts[1]);
                                            AssertClientHasHost(client7, readHosts[0]);
                                            AssertClientHasHost(client8, readHosts[1]);
                                        }
        }
예제 #2
0
        public async Task Does_throw_TimeoutException_when_PoolTimeout_exceeded()
        {
            await using IRedisClientsManagerAsync manager = new PooledRedisClientManager(testReadWriteHosts, testReadOnlyHosts,
                                                                                         new RedisClientManagerConfig
            {
                MaxWritePoolSize = 4,
                MaxReadPoolSize  = 4,
                AutoStart        = false,
            });
            ((PooledRedisClientManager)manager).PoolTimeout = 100;

            ((PooledRedisClientManager)manager).Start();

            var masters = 4.Times(i => manager.GetClientAsync());

            try
            {
                await manager.GetClientAsync();

                Assert.Fail("Should throw TimeoutException");
            }
            catch (TimeoutException ex)
            {
                Assert.That(ex.Message, Does.StartWith("Redis Timeout expired."));
            }

            for (int i = 0; i < 4; i++)
            {
                await manager.GetReadOnlyClientAsync();
            }

            try
            {
                await manager.GetReadOnlyClientAsync();

                Assert.Fail("Should throw TimeoutException");
            }
            catch (TimeoutException ex)
            {
                Assert.That(ex.Message, Does.StartWith("Redis Timeout expired."));
            }
        }
예제 #3
0
        public async Task Can_change_db_for_client_PooledRedisClientManager()
        {
            await using IRedisClientsManagerAsync db1 = new PooledRedisClientManager(1, new string[] { TestConfig.SingleHost });
            await using IRedisClientsManagerAsync db2 = new PooledRedisClientManager(2, new string[] { TestConfig.SingleHost });
            var val  = Environment.TickCount;
            var key  = "test" + val;
            var db1c = await db1.GetClientAsync();

            var db2c = await db2.GetClientAsync();

            try
            {
                await db1c.SetAsync(key, val);

                Assert.That(await db2c.GetAsync <int>(key), Is.EqualTo(0));
                Assert.That(await db1c.GetAsync <int>(key), Is.EqualTo(val));
            }
            finally
            {
                await db1c.RemoveAsync(key);
            }
        }