当前位置:网站首页>幂等性的处理
幂等性的处理
2022-04-23 15:37:00 【dengk2013】
幂等性是啥? 发一次接口调用与发多次相同的接口消息都能得到与预期相符的结果
假如有个接口是提供加工资的接口,如果调用一次加500块钱,如果不控制幂等性的问题,
一直调用接口,那么该员工的工资一直在加
//查询1号员工数据
Employee employee = employeeService.selectById(1);
//更新工资
employee.setSalary(employee.getSalary() + incrSalary);
//执行更新语句
employeeService.update(employee)
有什么问题? 对喽,每重发一次请求1号工资就会+500,幂等性就被破坏了
怎么解决? 传统办法是代码增加前置判断,也就是通过增加一个标志位和加薪时间
if(!员工已调薪 && 加薪时间+6个月<系统当前时间)
{
进行调薪
}
有什么不好? 需要前置判断的地方太多了,一不留神就漏了 这种技术问题不应该成为干扰程序员写业务代码的因素
我们需要一种无侵入的幂等解决方案 构建幂等表是我们的通用解决方案 让兄弟们专心的写CRUD就好啦

优点:后台服务无代码侵入,无需修改业务逻辑
缺点:前台应用要针对幂等进行改造 架构复杂度增加,需要额外部署Nginx、Redis
版权声明
本文为[dengk2013]所创,转载请带上原文链接,感谢
https://blog.csdn.net/u012222011/article/details/124352895
边栏推荐
猜你喜欢

Detailed explanation of kubernetes (XI) -- label and label selector

X509 certificate cer format to PEM format

网站建设与管理的基本概念

导入地址表分析(根据库文件名求出:导入函数数量、函数序号、函数名称)

Machine learning - logistic regression

考试考试自用

Advantages, disadvantages and selection of activation function

Explanation 2 of redis database (redis high availability, persistence and performance management)

The wechat applet optimizes the native request through the promise of ES6

Wechat applet customer service access to send and receive messages
随机推荐
推荐搜索 常用评价指标
G007-hwy-cc-estor-03 Huawei Dorado V6 storage simulator construction
MultiTimer v2 重构版本 | 一款可无限扩展的软件定时器
Mumu, go all the way
移动金融(自用)
Squid agent
基础贪心总结
PHP function
[backtrader source code analysis 18] Yahoo Py code comments and analysis (boring, interested in the code, you can refer to)
通过 PDO ODBC 将 PHP 连接到 MySQL
Demonstration meeting on startup and implementation scheme of swarm intelligence autonomous operation smart farm project
Deep learning - Super parameter setting
Collation of errors encountered in the use of redis shake
【递归之数的拆分】n分k,限定范围的拆分
【AI周报】英伟达用AI设计芯片;不完美的Transformer要克服自注意力的理论缺陷
php类与对象
el-tree实现只显示某一级复选框且单选
自主作业智慧农场创新论坛
How to design a good API interface?
码住收藏▏软件测试报告模板范文来了