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);
|
}
|
}
|