public class RedisTag {
/**
*
* @param tagName
* @param type 1、开始2、结束
* @param redisTemplate
* @return
*/
public static boolean tag(String tagName,String type, RedisTemplate<String,String> redisTemplate){
if(StringUtils.eq("1",type)){
Boolean aBoolean = redisTemplate.opsForValue().setIfAbsent(tagName, "1", 5, TimeUnit.MINUTES);
return Optional.ofNullable(aBoolean).orElse(false);
}else {
Boolean aBoolean = redisTemplate.opsForValue().setIfAbsent(tagName, "1", 5, TimeUnit.SECONDS);
Boolean aBoolean1 = Optional.ofNullable(aBoolean).orElse(true);
if(!aBoolean1){
try {
redisTemplate.delete(tagName);
}catch (Exception ignored){
}
}
return true;
}
}