public interface DistributedLock {
boolean getLock(String var1, String var2, int var3);//加锁 void unLock(String var1, String var2);//释放
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
// package com.pt.platform.core.redis.lock; import com.pt.platform.core.ehcache.ObtainPropertiesInfo;
import com.pt.platform.core.redis.JedisSentinelPool;
import com.pt.platform.core.redis.lock.DistributedLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.ShardedJedis;
import redis.clients.util.SafeEncoder; public class RedisLock implements DistributedLock {
private static final Logger logger = LoggerFactory.getLogger(RedisLock.class);
private static final int DEFAULT_EXPIRE_TIME = 60;
private static final String LOCK_KEY_PREFIX = "REDIS_LOCK";
private JedisSentinelPool pool; public RedisLock() {
} public JedisSentinelPool getPool() {
return this.pool;
} public void setPool(JedisSentinelPool pool) {
this.pool = pool;
} public boolean getLock(String module, String bizKey, int expireTime) {
if(module != null && !"".equals(module) && bizKey != null && !"".equals(bizKey)) {
if(this.getPool() != null) {
ShardedJedis jedis = null;
String lockKey = this.getLockKey(module, bizKey); boolean var10;
try {
jedis = (ShardedJedis)this.getPool().getResource();//获取到数据源
long e = System.currentTimeMillis();
long result = jedis.setnx(SafeEncoder.encode(lockKey), SafeEncoder.encode(e + "")).longValue();
if(result == 1L) {
if(expireTime > 0) {
jedis.expire(SafeEncoder.encode(lockKey), expireTime);
if(logger.isDebugEnabled()) {
logger.debug("key:" + lockKey + " locked and expire time:" + expireTime + "s");
}
} else {
jedis.expire(SafeEncoder.encode(lockKey), 60);
if(logger.isDebugEnabled()) {
logger.debug("key:" + lockKey + " locked and expire time:" + 60 + "s");
}
} var10 = true;
return var10;
} if(logger.isDebugEnabled()) {
logger.debug("key:" + lockKey + " has already bean locked");
} var10 = false;
} catch (Exception var14) {
logger.error("lock error", var14);
boolean var7 = false;
return var7;
} finally {
this.getPool().returnResource(jedis);
} return var10;
} else {
logger.error("jedisSentinelPool is null");
return true;
}
} else {
logger.error("parameters is null");
return false;
}
}

//删除key值释放锁
public void unLock(String module, String bizKey) {
if(module == null || "".equals(module) || bizKey == null || "".equals(bizKey)) {
logger.error("parameters is null");
} if(this.getPool() != null) {
ShardedJedis jedis = null;
String lockKey = this.getLockKey(module, bizKey); try {
jedis = (ShardedJedis)this.getPool().getResource();
jedis.del(SafeEncoder.encode(lockKey));
} catch (Exception var9) {
logger.error("unlock error", var9);
} finally {
this.getPool().returnResource(jedis);
}
} else {
logger.error("jedisSentinelPool is null");
} }

//组装key值
private String getLockKey(String module, String bizKey) {
StringBuffer sb = new StringBuffer();
sb.append("REDIS_LOCK").append(":").append(ObtainPropertiesInfo.getValByKey("app.code")).append(":").append(module).append(":").append(bizKey);
return sb.toString();
}
}
  private Map<String ,String> getResult(LaTFundRegDTO dto,UserInfo userInfo){
Map<String,String> map=null;
//加锁
if(redisLock.getLock(FundConstant.REDIS_LOCK_MODEL_FUND, dto.getCreditorRightsNo(), 120)) {
try{
if (FundConstant.FUND_STATUS_3.equals(dto.getFundStatus())) {
service.updateReFund(dto, userInfo);
} else if (FundConstant.FUND_STATUS_1.equals(dto.getFundStatus())) {
service.updatedoFundData(dto, userInfo);
}
}catch(Exception e){
e.printStackTrace();
map=new HashMap<String,String>();
map.put("id",dto.getCreditorRightsNo());
map.put("msg",e.getMessage());
logger.error("",e);
}finally{
redisLock.unLock(FundConstant.REDIS_LOCK_MODEL_FUND,dto.getCreditorRightsNo());
}
}else{
map=new HashMap<String,String>();
map.put("id",dto.getId()+"");
map.put("msg","不允许重复发起放款操作");
logger.error("不允许重复发起放款操作");
}
return map;
}

redis防止重复提交的更多相关文章

  1. 使用redis防止重复提交

    使用redis防止重复提交   其实主要思路是他的https://blog.csdn.net/u013378306/article/details/52944780 主要目前我的情况是,前后端分离的, ...

  2. Java使用Redis实现分布式锁来防止重复提交问题

    如何用消息系统避免分布式事务? - 少年阿宾 - BlogJavahttp://www.blogjava.net/stevenjohn/archive/2018/01/04/433004.html [ ...

  3. 【Redis使用系列】使用Redis做防止重复提交

    前言 在平时的开发中我们都需要处理重复提交的问题,避免业务出错或者产生脏数据,虽然可以通过前端控制但这并不是可以完全避免,最好的方式还是前后端均进行控制,这样的话就可以更有效,尽可能全面的去减少错误的 ...

  4. 浅谈C#在网络波动时防重复提交

    前几天,公司数据库出现了两条相同的数据,而且时间相同(毫秒也相同).排查原因,发现是网络波动造成了重复提交. 由于网络波动而重复提交的例子也比较多: 网络上,防重复提交的方法也很多,使用redis锁, ...

  5. Restful api 防止重复提交

    当前很多网站是前后分离的,前端(android,iso,h5)通过restful API 调用 后端服务器,这就存在一个问题,对于创建操作,比如购买某个商品,如果由于某种原因,手抖,控件bug,网络错 ...

  6. springmvc防止重复提交拦截器

    一.拦截器实现,ResubmitInterceptorHandler.java import org.apache.commons.lang3.StringUtils; import org.spri ...

  7. 防CSRF攻击:一场由重复提交的问题引发的前端后端测试口水战

    重复提交,这是一直以来都会存在的问题,当在网站某个接口调用缓慢的时候就会有可能引起表单重复提交的问题,不论form提交,还是ajax提交都会有这样的问题,最近在某社交app上看到这么一幕,这个团队没有 ...

  8. Token机制,防止web页面重复提交

    1.业务要求:页面的数据只能被点击提交一次 2.发生原因: 由于重复点击或者网络重发,或者nginx重发等情况会导致数据被重复提交 3.解决办法: 集群环境:采用token加redis(redis单线 ...

  9. 由防止表单重复提交引发的一系列问题--servletRequest的复制、body值的获取

    @Time:2019年1月4日 16:19:19 @Author:QGuo   背景:最开始打算写个防止表单重复提交的拦截器:网上见到一种不错的方式,比较合适前后端分离,校验在后台实现: 我在此基础上 ...

随机推荐

  1. 最全总结 | 聊聊 Python 办公自动化之 PPT(中)

    1. 前言 上一篇文章简单地介绍了 PPT 的文档结构,并使用 python-pptx 这个依赖库完成对 PPT 文档最基本的操作 最全总结 | 聊聊 Python 办公自动化之 PPT(上) 作为 ...

  2. css3 知识点积累

    -moz-    兼容火狐浏览器-webkit-  兼容chrome 和safari1.角度  transform:rotate(30dge)  水平线与div 第四象限30度  transform: ...

  3. YGGL.sql

    (将表复制粘贴至记事本,再用source命令导入到数据库中) CREATE TABLE `departments` ( `部门编号` char(3) NOT NULL COMMENT '部门编号', ...

  4. 分享一个的c++写的,模仿awk的框架类CAwkDoc

    这是我好多年前,模仿awk写的. awk大家都比较熟悉,使用awk处理文件,读取文件,分割字段这些工作awk自己帮你实现了. 程序员只要编写业务逻辑代码,并且awk还提供了很多常用的字符串操作函数,可 ...

  5. epoll的陷阱实践

    在使用epoll的时候,我们上篇文章epoll的陷阱大体介绍了epoll中会有哪些问题.这篇文章我们就针对必须要了解,也是绕不过去的陷阱进行实验,看看现象是什么,并且如何编写才能达到我们想要的效果. ...

  6. nodejs事件和事件循环详解

    目录 简介 nodejs中的事件循环 phase详解 timers pending callbacks idle, prepare poll轮询 check close callbacks setTi ...

  7. Redis Cluster 集群节点信息 维护篇(二)

    集群信息文件: # cluster 集群内部信息对应文件,由集群自动维护. /data/soft/redis/6379data/nodes-6379.conf 集群信息查看: ./redis-trib ...

  8. Kubernetes学习笔记之安装minikube并运行个简单应用程序

    前言:本笔记仅记录学习记录,可能存在错误!!!使用的环境是Ubuntu Desktop 20.04,也有用Windows 10 操作的,根据的文档是minikube的文档教程,链接:https://m ...

  9. Jenkins+windows+.netcore+git+iis自动化部署入门

    什么是自动化部署,就不介绍了,喜欢直接进入主题. 一. 所需环境: 1.系统为windows10 . 2.asp.net core3.1 runtime必须安装,因为我的代码是asp.net core ...

  10. ctfhub技能树—信息泄露—PHPINFO

    打开靶机 查看页面,是PHP info界面 只有这一个页面,查找一下有没有flag 拿到flag 浅谈ctf中phpinfo需要关注的点(转自先知社区) 1 https://xz.aliyun.com ...