sunpengfei
2025-11-19 7b47c91bcf89d667a5c99cfafe0d899280f7fbe3
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);
        }
    }
}