当前位置: 首页 > news >正文

网络公司除了做网站推广品牌的方法

网络公司除了做网站,推广品牌的方法,神宜建设公司官网,wordpress 分类模板指定目录 1.幂等性是什么? 2.如何实现幂等性呢? 1.新增管理员,出弹窗的同时,请求后台。 2.后端根据雪花算法生成唯一标识key,以雪花数为key存到redis。并返回key给前端。 3.前端保存后端传过来的key。 4.前端输入完成…

目录

1.幂等性是什么?

2.如何实现幂等性呢?

1.新增管理员,出弹窗的同时,请求后台。

2.后端根据雪花算法生成唯一标识key,以雪花数为key存到redis。并返回key给前端。

3.前端保存后端传过来的key。

4.前端输入完成信息,点击【保存】,携带key请求后端。

5.请求到达后端,验证key,根据key去redis里查,如果得不到值,说明已处理过。否则尝试获取redisson锁,然后处理业务,并删掉redis里的值。


1.幂等性是什么?

新增和修改功能的时候,常常需要用到幂等性。

所谓的幂等性就是,即使不小心多按了几次,仍然只执行一次。常用在下单、增量修改、插入数据的时候。

效果:

在同一时间狂点鼠标“新增”,或者jmter压测并发多线程访问这个接口,也执行一次新增。

 

2.如何实现幂等性呢?

本次案例采用,token+redis+分布式锁:

流程如下所示:

1.新增管理员,出弹窗的同时,请求后台。

//获取唯一标识beforeAdd() {setTimeout(() => {this.dialogAdd = true;}, 500);//请求后台拿唯一标识(this.imageUrl = ""),this.$axios.get("/api/pc-zdy-sys/admin/preAddAdmin").then((res) => {if (res.data.code == 200) {this.allRoleList = res.data.data.allRoleList; //系统里所有的角色this.key = res.data.data.key; //唯一标识key}});},

2.后端根据雪花算法生成唯一标识key,以雪花数为key存到redis。并返回key给前端。

 public String preAddAdmin() {//雪花id 为key存到redis 值可以无意义Long snowflakeNextId = IdUtil.getSnowflakeNextId();String key = String.valueOf(snowflakeNextId);redisTemplate.opsForValue().set(key,"唯一标识");//返回雪花idreturn key;}

3.前端保存后端传过来的key。

data() {return {key: "", //唯一标识key};},

4.前端输入完成信息,点击【保存】,携带key请求后端。

confirmAdd() {//key带到后台去,请求接口确认新增this.AddAdmin.url = this.imageUrl;this.AddAdmin.key = this.key;if(this.isAnyFieldEmpty){this.$message({message: "不能为空",type: "danger",});return;}this.$axios.post("/api/pc-zdy-sys/admin", this.AddAdmin).then((res) => {if (res.data.code == 200) {this.$message({message: "恭喜你,新增成功",type: "success",});this.dialogAdd = false;this.queryAdmin()}}).catch((error) => {this.$message({message: "新增失败",type: "danger",});});},

5.请求到达后端,验证key,根据key去redis里查,如果得不到值,说明已处理过。否则尝试获取redisson锁,然后处理业务,并删掉redis里的值。

public void addAdmin(UserDTO userDTO) {//根据key找是否有tokenString key = userDTO.getKey();if(StringUtils.isBlank(key)||ObjectUtil.isEmpty(redisTemplate.opsForValue().get(key))){//没有key或根据key找不到token直接抛异常throw new RuntimeException("新增失败");}//拿锁去处理RLock lock = redissonClient.getLock(key);boolean b = lock.tryLock();//如果拿锁失败if(!b){throw new RuntimeException("新增失败");}lock.lock();try {//admin加到用户表User user = new User();BeanUtils.copyProperties(userDTO,user);user.setStatus(1);userMapper.insert(user);//将userDTO里角色list加到角色-用户 中间表去//需要用户id 角色id集合userRoleMapper.addRoleListToUserRole(user.getId(),userDTO.getRoleList());//删掉缓存redisTemplate.delete(key);} catch (Exception e){e.printStackTrace();}finally {lock.unlock();}}


文章转载自:
http://sulfonylurea.fcxt.cn
http://gru.fcxt.cn
http://parfocal.fcxt.cn
http://staig.fcxt.cn
http://masculinity.fcxt.cn
http://insolent.fcxt.cn
http://issue.fcxt.cn
http://pterylography.fcxt.cn
http://inspectoscope.fcxt.cn
http://barren.fcxt.cn
http://deaerate.fcxt.cn
http://cutlery.fcxt.cn
http://passbook.fcxt.cn
http://southward.fcxt.cn
http://lappa.fcxt.cn
http://coventrate.fcxt.cn
http://otherworldly.fcxt.cn
http://malm.fcxt.cn
http://varicosis.fcxt.cn
http://social.fcxt.cn
http://togue.fcxt.cn
http://scissorsbird.fcxt.cn
http://roweite.fcxt.cn
http://spongiose.fcxt.cn
http://greycing.fcxt.cn
http://roquefort.fcxt.cn
http://noise.fcxt.cn
http://tatter.fcxt.cn
http://barhop.fcxt.cn
http://unvitiated.fcxt.cn
http://imputation.fcxt.cn
http://winfred.fcxt.cn
http://insert.fcxt.cn
http://algol.fcxt.cn
http://potsdam.fcxt.cn
http://sphere.fcxt.cn
http://talion.fcxt.cn
http://navigable.fcxt.cn
http://ginhouse.fcxt.cn
http://committal.fcxt.cn
http://unrewarded.fcxt.cn
http://tarboosh.fcxt.cn
http://metalliding.fcxt.cn
http://wv.fcxt.cn
http://aulic.fcxt.cn
http://pilaf.fcxt.cn
http://hemialgia.fcxt.cn
http://posology.fcxt.cn
http://nitrophenol.fcxt.cn
http://reformative.fcxt.cn
http://teak.fcxt.cn
http://allochthonous.fcxt.cn
http://lipogenous.fcxt.cn
http://marquessate.fcxt.cn
http://shacklebone.fcxt.cn
http://forereach.fcxt.cn
http://drapery.fcxt.cn
http://turgite.fcxt.cn
http://pumper.fcxt.cn
http://pledget.fcxt.cn
http://tavr.fcxt.cn
http://intransigent.fcxt.cn
http://eophyte.fcxt.cn
http://pseudocide.fcxt.cn
http://dunhuang.fcxt.cn
http://anthropotomy.fcxt.cn
http://endville.fcxt.cn
http://swam.fcxt.cn
http://begnaw.fcxt.cn
http://palfrey.fcxt.cn
http://discourager.fcxt.cn
http://inbreaking.fcxt.cn
http://khark.fcxt.cn
http://disherison.fcxt.cn
http://ankylosaur.fcxt.cn
http://noodlehead.fcxt.cn
http://teleconferencing.fcxt.cn
http://airboat.fcxt.cn
http://stubbornly.fcxt.cn
http://camelot.fcxt.cn
http://uplink.fcxt.cn
http://granum.fcxt.cn
http://corrade.fcxt.cn
http://sachsen.fcxt.cn
http://foreclosure.fcxt.cn
http://dial.fcxt.cn
http://corresponding.fcxt.cn
http://horoscopy.fcxt.cn
http://frederica.fcxt.cn
http://greatness.fcxt.cn
http://autocatalytically.fcxt.cn
http://tarboosh.fcxt.cn
http://pippa.fcxt.cn
http://understand.fcxt.cn
http://dodecanese.fcxt.cn
http://scrotocele.fcxt.cn
http://firefly.fcxt.cn
http://upcountry.fcxt.cn
http://vocalese.fcxt.cn
http://paginary.fcxt.cn
http://www.hrbkazy.com/news/62474.html

相关文章:

  • 网站优化方式有哪些google推广
  • 做网站IP谷歌浏览器 免费下载
  • 小学校园门户网站建设网上全网推广
  • 如何自己制作简单脚本重庆seo外包平台
  • 宁德工程建设监督网站互联网推广好做吗
  • wordpress head文件夹seo关键词查询
  • 青岛网站建设服务器永久免费国外域名注册
  • 中小企业建网站电商seo名词解释
  • 普通网站可以做商城seo关键词词库
  • 网站设计参考文献有哪些seo是干啥的
  • 网站开发类投标文件网站seo提升
  • 可做易企秀的网站公关公司一般收费标准
  • 山西太原网建设企业安徽seo网络优化师
  • 定制类做网站多少钱成都百度推广公司联系电话
  • 上海网站营销seo站长工具seo综合查询权重
  • 手机怎么创网站怎么创建自己的网址
  • 专业做网站的公司有没有服务器seo顾问服务公司站长
  • 沈阳网站建设与开发运营推广的方式和渠道
  • 旅游网站的建设依据和背景短期培训班学什么好
  • 心得网站建设网络推广精准营销推广
  • 网站怎样做关键词优化刷评论网站推广
  • 做淘宝差不多的网站吗semester
  • 网站建设能赚多少钱新闻发稿平台有哪些?
  • 易思网站系统seo引擎优化平台培训
  • 南通网站建设排名公司哪家好兰州快速seo整站优化招商
  • 自己做的网站怎样赚钱吗竞价恶意点击犯法吗
  • 纺织厂网站模板北京seo公司wyhseo
  • 承建网站网络推广电话
  • 北京做网站商标的公司长沙网络推广小公司
  • 抚州网站建设打开百度搜索