Pu Zhibing
昨天 e778f1ec4f911e0b6332432edca4650461ce5870
user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/util/RedisUtil.java
@@ -1,17 +1,10 @@
package com.supersavedriving.user.modular.system.util;
import com.supersavedriving.user.core.util.ToolUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.Pipeline;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.*;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
@@ -103,6 +96,36 @@
                int num1 = 1;
                while (num1 <= 10){
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    b = lock(5);
                    if(b){
                        return true;
                    }else{
                        num1++;
                    }
                }
                return false;
            }
            return b;
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            unlock();
        }
        return false;
    }
    public boolean lock(String key){
        try {
            boolean b = lock(key,5);
            if(!b){
                int num1 = 1;
                while (num1 <= 10){
                    try {
                        Thread.sleep(3000);//等待3秒
                    } catch (InterruptedException e) {
                        e.printStackTrace();
@@ -130,6 +153,18 @@
     * @param time
     * @return
     */
    public boolean lock(String key, int time){
        String uuid = UUID.randomUUID().toString();
        return lock(key, uuid, time);
    }
    /**
     * 获取redis锁
     * @param time
     * @return
     */
    public boolean lock(int time){
        String uuid = UUID.randomUUID().toString();
        return lock("redis", uuid, time);