Beispiel #1
0
        private async Task DoOverlappingLocksAsync()
        {
            using (var redisLockFactory = new RedisLockFactory(AllActiveEndPoints))
            {
                var resource = $"testredislock-{Guid.NewGuid()}";

                using (var firstLock = await redisLockFactory.CreateAsync(resource, TimeSpan.FromSeconds(30)))
                {
                    Assert.That(firstLock.IsAcquired, Is.True);

                    using (var secondLock = await redisLockFactory.CreateAsync(resource, TimeSpan.FromSeconds(30)))
                    {
                        Assert.That(secondLock.IsAcquired, Is.False);
                    }
                }
            }
        }
Beispiel #2
0
        public async Task <RedisLock> GetLockAsync()
        {
            using (var redisLock = await _redisLockFactory.CreateAsync(_resource, _expiry))
            {
                _redisLock = redisLock;

                if (redisLock.IsAcquired)
                {
                    Thread.Sleep(_interval);
                }
                return(redisLock);
            }
        }