Login
网站首页 > 文章中心 > 其它

redis防止重复提交_使用redis 防止数据重复提交

作者:小编 更新时间:2023-08-07 10:51:40 浏览量:130人看过

redis防止重复提交_使用redis 防止数据重复提交-图1

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) {
                        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;
}

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(); } catch (Exception var9) { logger.error("unlock error", var9); } finally { this.getPool().returnResource(jedis); } else { logger.error("jedisSentinelPool is null"); }

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 getResult(LaTFundRegDTO dto,UserInfo userInfo){
    Map map=null;
    //加锁
    if(redisLock.getLock(FundConstant.REDIS_LOCK_MODEL_FUND, dto.getCreditorRightsNo(), 120)) {
        try{
            if (FundConstant.FUND_STATUS_③equals(dto.getFundStatus())) {
            } else if (FundConstant.FUND_STATUS_1.equals(dto.getFundStatus())) {
        }catch(Exception e){
            map=new HashMap();
            map.put("id",dto.getCreditorRightsNo());
            map.put("msg",e.getMessage());
            logger.error("",e);
        }finally{
    }else{
        map=new HashMap();
        map.put("id",dto.getId()+"");
        map.put("msg","不允许重复发起放款操作");
        logger.error("不允许重复发起放款操作");
    return map;
}

以上就是土嘎嘎小编为大家整理的redis防止重复提交相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!

版权声明:倡导尊重与保护知识产权。未经许可,任何人不得复制、转载、或以其他方式使用本站《原创》内容,违者将追究其法律责任。本站文章内容,部分图片来源于网络,如有侵权,请联系我们修改或者删除处理。

编辑推荐

热门文章