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. 图解HTTP权威指南(五) | HTTP缓存

    作者简介 李先生(Lemon),高级运维工程师(自称),SRE专家(目标),梦想在35岁买一辆保时捷.喜欢钻研底层技术,认为底层基础才是王道.一切新技术都离不开操作系统(CPU.内存.磁盘).网络等. ...

  2. 循序渐进VUE+Element 前端应用开发(33)--- 邮件参数配置和模板邮件发送处理

    在系统处理中,有时候需要发送邮件通知用户,如新增用户的邮件确认,密码找回,以及常规订阅消息.通知等内容处理,都可以通过邮件的方式进行处理.本篇随笔介绍结合VUE+Element 前端,实现系统的邮件参 ...

  3. 浅谈ES6数组及对象的解构

    一.数组的解构,ES6的新特性,主要是方便操作数组,节省不必要的代码,提高代码质量. 上图例子中, example1: 之前想要获取数组中的值,只能挨个获取下标,然后取值 example2:ES6新特 ...

  4. 并发编程--锁--Lock和Synchronized

    说说对于 synchronized 关键字的了解? synchronized关键字解决的是多个线程之间访问资源的同步性: synchronized 关键字可以保证被它修饰的方法或者代码块在任意时刻只能 ...

  5. intel英特尔NUC主机bug大清除案例

    如果你的NUC进入HDMI无法在显示器显示,可以参考此文章的思路,尝试排除各种问题.接下来我讲述一下我的NUCbug清除历程. 我的NUC激动时刻 我的NUC是这个型号,直接上图了:英特尔(Intel ...

  6. MongoDB备份(mongoexport)与恢复(mongoimport)

    1.备份恢复工具介绍: mongoexport/mongoimport mongodump/mongorestore(本文未涉及) 2.备份工具区别在哪里? 2.1 mongoexport/mongo ...

  7. 给编译出的程序添加图标(exe的图标)

    安装依赖: go get github.com/akavel/rsrc 在对应程序的源码路径下创建manifest文件,图标也要放进去(xxx.ico), 命名:main.exe.manifest : ...

  8. MongoDB导出导入功能

    导出脚本: mongo_export.sh !#/bin/bash mongoexport -h x.x.x.x  --port 27017 -d database -c collection  -q ...

  9. Linux安装MYSQL并部署主从复制集群

    主节点部署 安装数据库 Ubuntu apt-get install mysql-server -y systemctl start mysql systemctl enabled mysql Cen ...

  10. Java 给Word不同页面设置不同背景

    Word文档中,可直接通过[设计]-[页面颜色]页面颜色,通过Java代码可参考如下设置方法: 1. 设置单一颜色背景 doc.getBackground().setType(BackgroundTy ...