添加分布式部署定时任务
This commit is contained in:
+35
@@ -1,10 +1,12 @@
|
||||
package com.jero.common.util;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.*;
|
||||
import org.springframework.data.redis.core.script.RedisScript;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
@@ -609,4 +611,37 @@ public class RedisUtil {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* setnx
|
||||
*/
|
||||
public boolean setnx(String key, String value) {
|
||||
try {
|
||||
return redisTemplate.opsForValue().setIfAbsent(key, value);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* setnx
|
||||
*/
|
||||
public boolean setnx(String key, String value,long time) {
|
||||
try {
|
||||
return redisTemplate.opsForValue().setIfAbsent(key,value, Duration.ofSeconds(time));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* eval
|
||||
*/
|
||||
public Boolean eval(RedisScript<Long> luaScripts, List<String> keys, String values) {
|
||||
Long flag = redisTemplate.execute(luaScripts, keys, values);
|
||||
//判断是不是为1
|
||||
return flag == 1L;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user