< Summary

Information
Class: Intentum.Distributed.Redis.RedisDistributedLock
Assembly: Intentum.Distributed.Redis
File(s): /home/runner/work/Intentum/Intentum/src/Intentum.Distributed.Redis/RedisDistributedLock.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 14
Coverable lines: 14
Total lines: 29
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%110%
AcquireAsync()100%110%
ReleaseAsync()100%110%

File(s)

/home/runner/work/Intentum/Intentum/src/Intentum.Distributed.Redis/RedisDistributedLock.cs

#LineLine coverage
 1using Intentum.Distributed.Locking;
 2using StackExchange.Redis;
 3
 4namespace Intentum.Distributed.Redis;
 5
 6public sealed class RedisDistributedLock : IDistributedLock
 7{
 8    private readonly IDatabase _db;
 9    private readonly string _keyPrefix;
 10
 011    public RedisDistributedLock(IConnectionMultiplexer connection, string keyPrefix = "intentum:lock:")
 012    {
 013        _db = connection.GetDatabase();
 014        _keyPrefix = keyPrefix;
 015    }
 16
 17    public async Task<bool> AcquireAsync(string key, TimeSpan timeout, CancellationToken cancellationToken = default)
 018    {
 019        var redisKey = $"{_keyPrefix}{key}";
 020        var token = Environment.MachineName + Guid.NewGuid().ToString("N");
 021        return await _db.LockTakeAsync(redisKey, token, timeout);
 022    }
 23
 24    public async Task ReleaseAsync(string key, CancellationToken cancellationToken = default)
 025    {
 026        var redisKey = $"{_keyPrefix}{key}";
 027        await _db.KeyDeleteAsync(redisKey);
 028    }
 29}