public ResponseEntity againJoin(String id, String bondsShortName) {
    
        final ImportLock lock = new ImportLock(String.format("join:Biding:" + id));
        if (!lock.tryLock()) {
            //防止接口同时多次点击return ResponseUtil.success();
        }
        try {
           
        } catch (Exception e) {
            throw new GException(e.getMessage());
        } finally {
            if (lock != null) {
                if (!lock.unlock()) {
                   
                }
            }
        }
    }
 
 
@Setter
@Getter
@ToString
public class ImportLock extends AbstractRedisLock {
    public final long expired = 1000 * 60 * 30L;
    private String key;
    private final String value = UUID.randomUUID().toString();
    public ImportLock(String key) {
        this.key = key;
    }
}
 
public abstract class AbstractRedisLock {
    abstract public String getKey();
    abstract public String getValue();
    abstract public long getExpired();
    public boolean tryLock() {
        return StringRedisCacheService.tryLock(getKey(), getValue(), getExpired());
    }
    public boolean unlock() {
        return StringRedisCacheService.unLock(getKey(), getValue());
    }
    public boolean simpleLock() {
        return StringRedisCacheService.simpleRedisLock(getKey(), getExpired());
    }
}
 
@Component
public class StringRedisCacheService {
    public static StringRedisTemplate stringRedisTemplate() {
        return SpringContextHolder.getBean(StringRedisTemplate.class);
    }
    public static void set(String key, String value, long time) {
        stringRedisTemplate().opsForValue().set(key, value, time, TimeUnit.SECONDS);
    }
    public static void set(String key, String value) {
        stringRedisTemplate().opsForValue().set(key, value);
    }
    public static String getAndSet(String key, String value) {
        return stringRedisTemplate().opsForValue().getAndSet(key, value);
    }
    public static void delete(String key) {
        stringRedisTemplate().delete(key);
    }
    public static String get(String key) {
        return stringRedisTemplate().opsForValue().get(key);
    }
    public static boolean hasKey(String key) {
        return stringRedisTemplate().hasKey(key);
    }
    public static void send2Pub(String topic, String msg) {
        stringRedisTemplate().convertAndSend(topic, msg);
    }
    /**
     * 增加值
     */
    public static Long incr(String key, long delta) {
        return stringRedisTemplate().opsForValue().increment(key, delta);
    }
    public static Long decr(String key, long delta) {
        return stringRedisTemplate().opsForValue().decrement(key, delta);
    }
    public static boolean simpleRedisLock(final String key, final long milliseconds) {
        final String lockValue = "1";
        return tryLock(key, lockValue, milliseconds);
    }
    public static boolean tryLock(String lockKey, String lockValue, long milliseconds) {
        StringRedisTemplate stringRedisTemplate = stringRedisTemplate();
        return stringRedisTemplate.execute((RedisCallback<Boolean>) connection -> {
            Charset utf8 = StandardCharsets.UTF_8;
            Object result = connection.execute("set",
                    lockKey.getBytes(utf8),
                    lockValue.getBytes(utf8),
                    "NX".getBytes(utf8),
                    "PX".getBytes(utf8),
                    String.valueOf(milliseconds).getBytes(utf8));
            return result != null;
        });
    }
    public static boolean unLock(String lockKey, String lockValue) {
        StringRedisTemplate stringRedisTemplate = stringRedisTemplate();
        DefaultRedisScript<Long> script = new DefaultRedisScript<>();
        script.setResultType(Long.class);
        script.setScriptText("if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end");
        Long rs = stringRedisTemplate.execute(script, Collections.singletonList(lockKey), lockValue);
        return Long.valueOf(1L).equals(rs);
    }
}