All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.yueshutong.springbootstartercurrentlimiting.common.RedisLockUtil Maven / Gradle / Ivy

There is a newer version: 0.1.1.RELEASE
Show newest version
package cn.yueshutong.springbootstartercurrentlimiting.common;

import org.springframework.data.redis.core.StringRedisTemplate;

import java.util.concurrent.TimeUnit;

public class RedisLockUtil {
    /**
     * 获取锁,获取不到立即失败
     */
    public static boolean tryLockFailed(StringRedisTemplate template,String Key,String Value) {
        Boolean b = template.opsForValue().setIfAbsent(Key, Value);
        return b == null ? false : b;
    }

    /**
     * 释放锁
     */
    public static void releaseLock(StringRedisTemplate template,String LOCK) {
        template.delete(LOCK);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy