当前位置:网站首页>幂等性的处理
幂等性的处理
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
边栏推荐
- T2 icloud calendar cannot be synchronized
- PHP 的运算符
- Openstack theoretical knowledge
- JVM-第2章-类加载子系统(Class Loader Subsystem)
- adobe illustrator 菜單中英文對照
- Pytorch中named_parameters、named_children、named_modules函数
- Sword finger offer (2) -- for Huawei
- PHP PDO ODBC将一个文件夹的文件装载到MySQL数据库BLOB列,并将BLOB列下载到另一个文件夹
- [backtrader source code analysis 18] Yahoo Py code comments and analysis (boring, interested in the code, you can refer to)
- X509 certificate cer format to PEM format
猜你喜欢

Mumu, go all the way

Sword finger offer (2) -- for Huawei

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

函数(第一部分)

Cookie&Session

cadence SPB17. 4 - Active Class and Subclass

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

MySQL InnoDB transaction

Sorting and replying to questions related to transformer

字节面试 transformer相关问题 整理复盘
随机推荐
cadence SPB17.4 - Active Class and Subclass
el-tree实现只显示某一级复选框且单选
Mysql database explanation (10)
移动app测试如何进行?
Rsync + inotify remote synchronization
控制结构(一)
HJ31 单词倒排
Openstack theoretical knowledge
码住收藏▏软件测试报告模板范文来了
Collation of errors encountered in the use of redis shake
Sorting and replying to questions related to transformer
JSON date time date format
Deeply learn the skills of parameter adjustment
Special analysis of China's digital technology in 2022
Functions (Part I)
My raspberry PI zero 2W toss notes to record some problems and solutions
Deep learning - Super parameter setting
Connectez PHP à MySQL via aodbc
Detailed explanation of MySQL connection query
php函数