using Medallion.Threading;
|
using Medallion.Threading.Redis;
|
using System;
|
using System.Threading;
|
using System.Threading.Tasks;
|
|
namespace ApiTools.Core
|
{
|
public static class DistributedLock
|
{
|
public static ValueTask<IDistributedSynchronizationHandle> TryAcquireAsync(
|
this IDistributedLockProvider provider,
|
string lockKey, TimeSpan timeout, CancellationToken cancellationToken = default)
|
{
|
lockKey = $"DistributedLock:{lockKey}";
|
var @lock = provider.CreateLock(lockKey);
|
return @lock.TryAcquireAsync(timeout, cancellationToken);
|
}
|
}
|
}
|