Beispiel #1
0
        public void Does_Timeout_with_repeated_SocketException()
        {
            RedisConfig.Reset();
            RedisConfig.DefaultRetryTimeout = 100;

            var redis = new RedisClient(RedisConfig.DefaultHost);

            redis.FlushAll();

            Assert.That(redis.IncrementValue("retryCounter"), Is.EqualTo(1));

            redis.OnBeforeFlush = () =>
            {
                throw new SocketException();
            };

            try
            {
                redis.IncrementValue("retryCounter");
                Assert.Fail("Should throw");
            }
            catch (RedisException ex)
            {
                Assert.That(ex.Message, Is.StringStarting("Exceeded timeout"));

                redis.OnBeforeFlush = null;
                Assert.That(redis.Get <int>("retryCounter"), Is.EqualTo(1));

                Assert.That(RedisStats.TotalRetryCount, Is.GreaterThan(1));
                Assert.That(RedisStats.TotalRetrySuccess, Is.EqualTo(0));
                Assert.That(RedisStats.TotalRetryTimedout, Is.EqualTo(1));
            }

            RedisConfig.Reset();
        }
Beispiel #2
0
        public void Does_not_retry_when_RetryTimeout_is_Zero()
        {
            RedisConfig.Reset();
            RedisConfig.DefaultRetryTimeout = 0;

            var redis = new RedisClient(Config.MasterHost);

            redis.FlushAll();

            Assert.That(redis.IncrementValue("retryCounter"), Is.EqualTo(1));

            redis.OnBeforeFlush = () => throw new SocketException();

            try {
                redis.IncrementValue("retryCounter");
                Assert.Fail("Should throw");
            } catch (Exception ex) {
                Assert.That(ex.Message, Does.StartWith("Exceeded timeout"));

                redis.OnBeforeFlush = null;
                Assert.That(redis.Get <int>("retryCounter"), Is.EqualTo(1));

                Assert.That(RedisStats.TotalRetryCount, Is.EqualTo(0));
                Assert.That(RedisStats.TotalRetrySuccess, Is.EqualTo(0));
                Assert.That(RedisStats.TotalRetryTimedout, Is.EqualTo(1));
            }

            RedisConfig.Reset();
        }
        public async Task Does_Timeout_with_repeated_SocketException()
        {
            RedisConfig.Reset();
            RedisConfig.DefaultRetryTimeout = 100;

            var redis = new RedisClient(RedisConfig.DefaultHost).ForAsyncOnly();
            await redis.FlushAllAsync();

            Assert.That(await redis.IncrementValueAsync("retryCounter"), Is.EqualTo(1));

            ((RedisClient)redis).OnBeforeFlush = () =>
            {
                throw new SocketException();
            };

            try
            {
                await redis.IncrementValueAsync("retryCounter");

                Assert.Fail("Should throw");
            }
            catch (RedisException ex)
            {
                Assert.That(ex.Message, Does.StartWith("Exceeded timeout"));

                ((RedisClient)redis).OnBeforeFlush = null;
                Assert.That(await redis.GetAsync <int>("retryCounter"), Is.EqualTo(1));

                Assert.That(RedisStats.TotalRetryCount, Is.GreaterThan(1));
                Assert.That(RedisStats.TotalRetrySuccess, Is.EqualTo(0));
                Assert.That(RedisStats.TotalRetryTimedout, Is.EqualTo(1));
            }

            RedisConfig.Reset();
        }
 public void Dispose()
 {
     DisposePool();
     Pool = null;
     RedisConfig.Reset();
     GC.SuppressFinalize(this);
 }
Beispiel #5
0
        public async Task Can_Delete_All_Items_multiple_batches()
        {
            // Clear previous usage
            await RedisAsync.DeleteAsync(RedisRaw.GetTypeIdsSetKey <CacheRecord>());

            var cachedRecord = new CacheRecord
            {
                Id       = "key",
                Children =
                {
                    new CacheRecordChild {
                        Id = "childKey", Data = "data"
                    }
                }
            };

            var exists = RedisRaw.Exists(RedisRaw.GetTypeIdsSetKey(typeof(CacheRecord)));

            Assert.That(exists, Is.EqualTo(0));

            await RedisTyped.StoreAsync(cachedRecord);

            exists = RedisRaw.Exists(RedisRaw.GetTypeIdsSetKey(typeof(CacheRecord)));
            Assert.That(exists, Is.EqualTo(1));

            RedisConfig.CommandKeysBatchSize = 5;

            for (int i = 0; i < 50; i++)
            {
                cachedRecord.Id = "key" + i;
                await RedisTyped.StoreAsync(cachedRecord);
            }

            Assert.That(await RedisTyped.GetByIdAsync("key"), Is.Not.Null);

            await RedisTyped.DeleteAllAsync();

            Assert.That(await RedisTyped.GetByIdAsync("key"), Is.Null);

            exists = RedisRaw.Exists(RedisRaw.GetTypeIdsSetKey(typeof(CacheRecord)));
            Assert.That(exists, Is.EqualTo(0));

            RedisConfig.Reset();
        }