优化下单redis锁

This commit is contained in:
大灰灰
2022-09-15 01:46:58 +08:00
parent 5494608f7a
commit 673628ed10

View File

@@ -159,7 +159,8 @@ namespace CoreCms.Net.Web.WebApi.Controllers
var jm = new WebApiCallBack();
var lockKey = "LOCK_CreateOrder:user_" + _user.ID;
var redisUserLock = await _redisOperationRepository.LockTakeAsync(lockKey, _user.ID.ToString(), TimeSpan.FromSeconds(10));
var lockHolder = Guid.NewGuid().ToString("N"); //锁持有者
var redisUserLock = await _redisOperationRepository.LockTakeAsync(lockKey, lockHolder, TimeSpan.FromSeconds(10));
if (redisUserLock)
{
try
@@ -226,7 +227,7 @@ namespace CoreCms.Net.Web.WebApi.Controllers
}
finally
{
await _redisOperationRepository.LockReleaseAsync(lockKey, _user.ID.ToString());
await _redisOperationRepository.LockReleaseAsync(lockKey, lockHolder);
}
}
else