redis防止重复提交
来源:互联网 发布:sony软件下载 编辑:程序博客网 时间:2024/06/16 15:55
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; }
阅读全文
0 0
- redis防止重复提交
- redis setNX 锁来实现防止重复提交的
- 防止重复提交数据
- 防止重复提交
- struts防止重复提交
- 防止表单重复提交
- 防止重复提交
- 防止重复提交表单
- javascript 防止重复提交
- Struts防止重复提交
- 防止struts重复提交
- 防止重复提交
- javascript 防止重复提交
- Struts2 防止重复提交
- 防止重复提交
- 防止servlet重复提交
- 防止重复提交
- Webwork防止重复提交
- 查询某个数据库所有表的表名、表字段等
- android error: undefined reference to 的错误分析
- 解决eclipse卡死问题、eclipse内存配置
- 深入理解Java虚拟机——JVM垃圾回收机制和垃圾收集器详解
- Oracle随机查询n条数据
- redis防止重复提交
- C语言知识点梳理(1)
- storm运行机制自我复述
- Android 手机卡了怎么办
- JVM-Class类文件的结构
- 使用redis计数器防止并发请求
- js的基本语法
- ATL COM开发学习
- HTML鼠标在单元格上单击,单元格反色,可以利用方向键移动反色效果