Commit 1b142b47 by 田超

Merge branch 'feature/1004590' into 'master'

feat: [1004590] 广告平台系统

See merge request rays/pcloud-common-parent!200
parents 23082ec7 6dd14a1a
...@@ -6,6 +6,7 @@ package com.pcloud.common.utils.cache.redis; ...@@ -6,6 +6,7 @@ package com.pcloud.common.utils.cache.redis;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -152,6 +153,37 @@ public class JedisClusterUtils { ...@@ -152,6 +153,37 @@ public class JedisClusterUtils {
} }
/** /**
* 保存一个字符串到redis中并指定过期时间
* nxxx: NX 不存在则添加
* expx: EX:秒;PX:毫秒;
*/
public static boolean set(String key, String value, String nxxx, String expx, Integer seconds) {
try {
seconds = Optional.ofNullable(seconds).orElse(60);
String result = jedisCluster.set(key, value, nxxx, expx, seconds);
return "OK".equalsIgnoreCase(result);
} catch (Exception e) {
LOGGER.warn("jedis缓存保存失败:" + e.getMessage(), e);
return false;
}
}
/**
* 加锁
*/
public static boolean lock(String key, Integer seconds) {
try {
seconds = Optional.ofNullable(seconds).orElse(60);
String result = jedisCluster.set(key, String.valueOf(System.currentTimeMillis()), "NX", "EX", seconds);
return "OK".equalsIgnoreCase(result);
} catch (Exception e) {
LOGGER.warn("jedis缓存保存失败:" + e.getMessage(), e);
return false;
}
}
/**
* 保存一个字符串到redis中,长期有效 * 保存一个字符串到redis中,长期有效
* *
* @param objecKey 键 * @param objecKey 键
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment