mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2026-02-05 12:19:48 +08:00
优化下单redis锁
This commit is contained in:
@@ -159,7 +159,8 @@ namespace CoreCms.Net.Web.WebApi.Controllers
|
|||||||
var jm = new WebApiCallBack();
|
var jm = new WebApiCallBack();
|
||||||
|
|
||||||
var lockKey = "LOCK_CreateOrder:user_" + _user.ID;
|
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)
|
if (redisUserLock)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -226,7 +227,7 @@ namespace CoreCms.Net.Web.WebApi.Controllers
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
await _redisOperationRepository.LockReleaseAsync(lockKey, _user.ID.ToString());
|
await _redisOperationRepository.LockReleaseAsync(lockKey, lockHolder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user