sunpengfei
2025-12-01 6396dac27ca99e84a2e3c772fb079bceddf67ff8
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);
        }
    }
}