public async Task Equeue_Parallels_Calls_Should_Use_All_The_Pool() { const string cacheKey = "my cache key"; const int maxNumberOfIterations = 5000; var errors = new bool[maxNumberOfIterations]; await sut .GetConnection() .GetDatabase(0) .StringSetAsync(cacheKey, "my cache value"); Parallel.For(0, maxNumberOfIterations, (i, state) => { try { sut .GetConnection() .GetDatabase(0) .StringGet(cacheKey); errors[i] = false; } catch (RedisTimeoutException exc) { errors[i] = true; output.WriteLine(exc.Message); } }); Assert.Equal(0, errors.Count(x => x)); Assert.Equal(maxNumberOfIterations, errors.Count(x => !x)); }
public async Task Open_Tons_of_concurrent_connections() { var sut = new RedisCacheConnectionPoolManager(new RedisConfiguration() { AbortOnConnectFail = false, Hosts = new RedisHost[] { new RedisHost() { Host = "localhost", Port = 6379 } }, AllowAdmin = true, ConnectTimeout = 5000, Database = 8, PoolSize = 10, ServerEnumerationStrategy = new ServerEnumerationStrategy() { Mode = ServerEnumerationStrategy.ModeOptions.All, TargetRole = ServerEnumerationStrategy.TargetRoleOptions.Any, UnreachableServerAction = ServerEnumerationStrategy.UnreachableServerActionOptions.Throw } }); await sut.GetConnection().GetDatabase().StringSetAsync("key", "value"); var conn = sut.GetConnection(); Parallel.For(0, 1000, x => { try { sut.GetConnection().GetDatabase().StringGet("key"); } catch (Exception exc) { output.WriteLine($"Index: {x} - Exception {exc.ToString()}"); throw; } }); }
public void Test_using_multiple_times_work() { var lockName = "first-lock"; // ensure that no stale keys are left _connectionPool.GetConnection().GetDatabase().KeyDelete(lockName); var locker = new RedisDistributedAppLockProvider(_connectionPool); using (locker.Acquire(lockName)) { // mutual exclusion scope here } using (locker.Acquire(lockName)) { // mutual exclusion scope here } using (locker.Acquire(lockName)) { // mutual exclusion scope here } }