|
@@ -6,6 +6,7 @@ import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
@@ -22,6 +23,8 @@ public final class RedisUtil {
|
|
|
@Autowired
|
|
|
private RedisTemplate<String, Object> redisTemplate;
|
|
|
|
|
|
+ public static Map<String, Object> static_map = new HashMap<>();
|
|
|
+
|
|
|
// =============================common============================
|
|
|
|
|
|
/**
|
|
@@ -92,7 +95,7 @@ public final class RedisUtil {
|
|
|
* @param key 键
|
|
|
* @return 值
|
|
|
*/
|
|
|
- private Object get(String key) {
|
|
|
+ public Object get(String key) {
|
|
|
return key == null ? null : redisTemplate.opsForValue().get(key);
|
|
|
}
|
|
|
|
|
@@ -103,7 +106,7 @@ public final class RedisUtil {
|
|
|
* @param value 值
|
|
|
* @return true成功 false失败
|
|
|
*/
|
|
|
- private boolean set(String key, Object value) {
|
|
|
+ public boolean set(String key, Object value) {
|
|
|
try {
|
|
|
redisTemplate.opsForValue().set(key, value);
|
|
|
return true;
|
|
@@ -122,7 +125,7 @@ public final class RedisUtil {
|
|
|
* @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期
|
|
|
* @return true成功 false 失败
|
|
|
*/
|
|
|
- private boolean set(String key, Object value, long time) {
|
|
|
+ public boolean set(String key, Object value, long time) {
|
|
|
try {
|
|
|
if (time > 0) {
|
|
|
redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
|
|
@@ -466,7 +469,6 @@ public final class RedisUtil {
|
|
|
*
|
|
|
* @param key 键
|
|
|
* @param value 值
|
|
|
- * @param time 时间(秒)
|
|
|
* @return
|
|
|
*/
|
|
|
private boolean lSet(String key, Object value) {
|
|
@@ -505,7 +507,6 @@ public final class RedisUtil {
|
|
|
*
|
|
|
* @param key 键
|
|
|
* @param value 值
|
|
|
- * @param time 时间(秒)
|
|
|
* @return
|
|
|
*/
|
|
|
private boolean lSet(String key, List<Object> value) {
|
|
@@ -584,11 +585,12 @@ public final class RedisUtil {
|
|
|
*/
|
|
|
public <T> T getJsonStringValue(String key) {
|
|
|
try {
|
|
|
- Object valObj = get(key);
|
|
|
- if (valObj != null && valObj.getClass().getName().indexOf("String") > -1) {
|
|
|
- return (T) FastJsonUtils.getJsonToBean(valObj.toString(), Object.class);
|
|
|
- }
|
|
|
- return null;
|
|
|
+// Object valObj = get(key);
|
|
|
+// if (valObj != null && valObj.getClass().getName().indexOf("String") > -1) {
|
|
|
+// return (T) FastJsonUtils.getJsonToBean(valObj.toString(), Object.class);
|
|
|
+// }
|
|
|
+// return null;
|
|
|
+ return (T)static_map.get(key);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
return null;
|
|
@@ -601,9 +603,10 @@ public final class RedisUtil {
|
|
|
* @param key
|
|
|
* @param value
|
|
|
*/
|
|
|
- public void setJsonStringValue(String key, Object value) {
|
|
|
+ public <T> void setJsonStringValue(String key, Object value) {
|
|
|
try {
|
|
|
- set(key, FastJsonUtils.getBeanToJson(value));
|
|
|
+ static_map.put(key, value);
|
|
|
+// set(key, FastJsonUtils.getBeanToJson(value));
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|