|
|
|
@ -13,9 +13,9 @@ import java.util.concurrent.TimeUnit; |
|
|
|
@Component |
|
|
|
public class RedisUtils { |
|
|
|
@Autowired |
|
|
|
private RedisTemplate<String, Object> redisTemplate; |
|
|
|
private static RedisTemplate<String, Object> redisTemplate; |
|
|
|
@Autowired |
|
|
|
private ValueOperations<String, String> valueOperations; |
|
|
|
private static ValueOperations<String, String> valueOperations; |
|
|
|
@Autowired |
|
|
|
private HashOperations<String, String, Object> hashOperations; |
|
|
|
@Autowired |
|
|
|
@ -36,7 +36,7 @@ public class RedisUtils { |
|
|
|
* @param value |
|
|
|
* @param expire |
|
|
|
*/ |
|
|
|
public void set(String key, Object value, long expire){ |
|
|
|
public static void set(String key, Object value, long expire){ |
|
|
|
valueOperations.set(key, toJson(value)); |
|
|
|
if(expire != NOT_EXPIRE){ |
|
|
|
redisTemplate.expire(key, expire, TimeUnit.SECONDS); |
|
|
|
@ -48,7 +48,7 @@ public class RedisUtils { |
|
|
|
* @param key |
|
|
|
* @param value |
|
|
|
*/ |
|
|
|
public void set(String key, Object value){ |
|
|
|
public static void set(String key, Object value){ |
|
|
|
set(key, value, DEFAULT_EXPIRE); |
|
|
|
} |
|
|
|
|
|
|
|
@ -72,7 +72,7 @@ public class RedisUtils { |
|
|
|
return get(key, clazz, NOT_EXPIRE); |
|
|
|
} |
|
|
|
|
|
|
|
public String get(String key, long expire) { |
|
|
|
public static String get(String key, long expire) { |
|
|
|
String value = valueOperations.get(key); |
|
|
|
if(expire != NOT_EXPIRE){ |
|
|
|
redisTemplate.expire(key, expire, TimeUnit.SECONDS); |
|
|
|
@ -80,7 +80,7 @@ public class RedisUtils { |
|
|
|
return value; |
|
|
|
} |
|
|
|
|
|
|
|
public String get(String key) { |
|
|
|
public static String get(String key) { |
|
|
|
return get(key, NOT_EXPIRE); |
|
|
|
} |
|
|
|
|
|
|
|
@ -91,7 +91,7 @@ public class RedisUtils { |
|
|
|
/** |
|
|
|
* Object转成JSON数据 |
|
|
|
*/ |
|
|
|
private String toJson(Object object){ |
|
|
|
private static String toJson(Object object){ |
|
|
|
if(object instanceof Integer || object instanceof Long || object instanceof Float || |
|
|
|
object instanceof Double || object instanceof Boolean || object instanceof String){ |
|
|
|
return String.valueOf(object); |
|
|
|
|