public ResultBean issue(String originID, final Long userID, final String fromIp) { try { if (!cacheSessionStorage.lock(ISSUING_LOCK + userID)) { return ResultBean.failed(Result.GLOBAL.FAIL.getCode(), "由于当前正在提现申请等原因,提现额度可能发生变化,发标失败,请稍后重试。"); } Subject subjectDraft = subjectDraftDAO.getByOriginID(originID); int limitCategory = subjectDraft.getLimitCategory().intValue(); if (LimitCategory.NET_VALUE.getType() == limitCategory) { return issueNetValue(originID, userID, fromIp); } else if (LimitCategory.CREDIT_LIMIT.getType() == limitCategory) { return issueCredit(originID, userID, fromIp); } else if (LimitCategory.FAST_LIMIT.getType() == limitCategory || LimitCategory.SPECIFIC.getType() == limitCategory || LimitCategory.DISCUSS.getType() == limitCategory || LimitCategory.ESSENCE.getType() == limitCategory || LimitCategory.GONGXIN.getType() == limitCategory) { return issueFastLoan(originID, userID, fromIp); } else if (LimitCategory.ASSETS_LIMIT.getType() == limitCategory) { return issueAssets(originID, userID, fromIp); } else { throw new UserException(BeanCode.GLOBAL.FAIL.getCode(), "发标类型不存在!"); } }catch (Exception e){ throw new UserException(BeanCode.GLOBAL.FAIL.getCode(), e.getMessage()); }finally { cacheSessionStorage.unlock(ISSUING_LOCK + userID); } } 2.除了使用redis锁行,还有利用数据库行锁,如果要锁的表比较大,而且只是记录一个业务操作, 通常使用中间表,表示这个业务状态,加行锁。
利用redis缓存锁记录,数据库锁行
最新推荐文章于 2024-10-31 17:18:11 发布
本文介绍了一种发标流程的实现方式,并针对并发场景讨论了如何使用Redis锁及数据库行锁来确保业务操作的一致性和准确性。通过不同的发标类型,展示了具体的发标逻辑处理。
1746

被折叠的 条评论
为什么被折叠?



