wanshenmean
4 天以前 64a2aa2301946f777659239247233e47ad1e3076
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
namespace WIDESEAWCS_RedisService.Lock
{
    public interface IDistributedLockService
    {
        /// <summary>
        /// 获取分布式锁
        /// </summary>
        /// <param name="lockKey">锁的Key</param>
        /// <param name="expiry">锁过期时间</param>
        /// <param name="waitTimeout">等待获取锁的超时时间</param>
        /// <returns>锁Token,释放时需要传入;获取失败返回null</returns>
        string? AcquireLock(string lockKey, TimeSpan expiry, TimeSpan? waitTimeout = null);
 
        /// <summary>
        /// 释放分布式锁
        /// </summary>
        bool ReleaseLock(string lockKey, string lockToken);
 
        /// <summary>
        /// 续期锁
        /// </summary>
        bool RenewLock(string lockKey, string lockToken, TimeSpan expiry);
 
        /// <summary>
        /// 使用锁执行操作
        /// </summary>
        T? ExecuteWithLock<T>(string lockKey, TimeSpan expiry, Func<T> action, TimeSpan? waitTimeout = null);
 
        /// <summary>
        /// 使用锁执行操作(无返回值)
        /// </summary>
        bool ExecuteWithLock(string lockKey, TimeSpan expiry, Action action, TimeSpan? waitTimeout = null);
    }
}