DistributedLeaseManager
2.0.0
一個簡單的C#/。網絡分佈式租賃/鎖管理器(DLM)實現。
受https://github.com/fbeltrao/azfunctions-distributed-locking的啟發
通過按照其讀書說明來安裝租賃存儲實現之一:
在您的控制器/服務中註入IDistributedLeaseManager ,並調用TryAcquireLease方法。驗證結果是否成功 - 如果是成功,則可以繼續操作;否則,其他人已獲得租約:
await using var leaseResult = await leaseManager . TryAcquireLease ( resourceId , TimeSpan . FromSeconds ( 5 ) ) ;
if ( ! leaseResult . IsSuccessful )
{
// Someone else has required the lease for the resource.
// You may want to either retry the acqusition or abort the operation.
}
else
{
// You are the lease owner now and can safely process the resource.
// The lease will be released either when the leaseResult gets disposed
// or when the lease expires (in the example above, in 5 seconds)
} 如果您想使用與作者提供的租賃存儲不同的租賃存儲,請在項目中添加DistributedLeaseManager.Core庫並實現相應的接口(請參見任何現有實現作為示例)。
隨意打開PR,以您的更改將其包含在包裝中!