Distributed locking
Obtaining and acquiring locks
public class FeedService
{
private readonly IDistributedLockProvider _locks;
public FeedService(IDistributedLockProvider locks) => _locks = locks;
public async Task GenerateAsync()
{
var @lock = _locks.GetLock("feeds:generate");
await using (await @lock.AcquireAsync())
{
// Critical section. Only one node can execute this at a time.
}
}
}Implementations
Last updated
Was this helpful?