lijin
2025-11-20 df6224a4e27e0dadc648cc51ff362e2d7e24a034
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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);
        }
    }
}