|
|
@@ -29,7 +29,6 @@ public class RedisUtil {
|
|
|
|
|
|
private static StringRedisTemplate stringRedisTemplate = SpringContextUtils.getBean("stringRedisTemplate",StringRedisTemplate.class);
|
|
|
|
|
|
-
|
|
|
//=============================common============================
|
|
|
/**
|
|
|
* 指定缓存失效时间
|
|
|
@@ -118,6 +117,22 @@ public class RedisUtil {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 快速获取锁(不重试)
|
|
|
+ */
|
|
|
+ public static boolean tryLockFast(String key,Object value,long time) {
|
|
|
+ try {
|
|
|
+ Boolean result = redisTemplate.opsForValue().setIfAbsent(
|
|
|
+ key,
|
|
|
+ value,
|
|
|
+ time,
|
|
|
+ TimeUnit.SECONDS
|
|
|
+ );
|
|
|
+ return Boolean.TRUE.equals(result);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 递增 此时value值必须为int类型 否则报错
|