|
@@ -2,9 +2,11 @@ package com.yohoufo.product.cache; |
|
@@ -2,9 +2,11 @@ package com.yohoufo.product.cache; |
2
|
|
2
|
|
3
|
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
|
3
|
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
|
4
|
import com.yohoufo.common.cache.CacheClient;
|
4
|
import com.yohoufo.common.cache.CacheClient;
|
|
|
5
|
+import com.yohoufo.common.cache.CachekeyParamsAndValue;
|
5
|
import org.springframework.beans.factory.annotation.Autowired;
|
6
|
import org.springframework.beans.factory.annotation.Autowired;
|
6
|
import org.springframework.stereotype.Service;
|
7
|
import org.springframework.stereotype.Service;
|
7
|
|
8
|
|
|
|
9
|
+import java.util.HashMap;
|
8
|
import java.util.Map;
|
10
|
import java.util.Map;
|
9
|
|
11
|
|
10
|
/**
|
12
|
/**
|
|
@@ -21,7 +23,7 @@ public class UfoProductCacheService { |
|
@@ -21,7 +23,7 @@ public class UfoProductCacheService { |
21
|
* @param value 缓存的值
|
23
|
* @param value 缓存的值
|
22
|
* @param keyParams 缓存key可变的参数列表 可空
|
24
|
* @param keyParams 缓存key可变的参数列表 可空
|
23
|
*/
|
25
|
*/
|
24
|
- public void setCacheByString(UfoProductCacheKeyEnum cacheKeyEnum, Object value, String... keyParams) {
|
26
|
+ public void setCacheByString(UfoProductCacheKeyEnum cacheKeyEnum, Object value, Object... keyParams) {
|
25
|
RedisKeyBuilder redisKeyBuilder = getRedisKeyBuilder(cacheKeyEnum, keyParams);
|
27
|
RedisKeyBuilder redisKeyBuilder = getRedisKeyBuilder(cacheKeyEnum, keyParams);
|
26
|
cacheClient.setEx(redisKeyBuilder, value, cacheKeyEnum.getExpireSecondTime());
|
28
|
cacheClient.setEx(redisKeyBuilder, value, cacheKeyEnum.getExpireSecondTime());
|
27
|
}
|
29
|
}
|
|
@@ -33,9 +35,13 @@ public class UfoProductCacheService { |
|
@@ -33,9 +35,13 @@ public class UfoProductCacheService { |
33
|
* @param value 缓存的值
|
35
|
* @param value 缓存的值
|
34
|
* @param keyParams 缓存key可变的参数列表 可空
|
36
|
* @param keyParams 缓存key可变的参数列表 可空
|
35
|
*/
|
37
|
*/
|
36
|
- public void msetCacheByString(UfoProductCacheKeyEnum cacheKeyEnum, Object value, String... keyParams) {
|
|
|
37
|
- RedisKeyBuilder redisKeyBuilder = getRedisKeyBuilder(cacheKeyEnum, keyParams);
|
|
|
38
|
- Map<RedisKeyBuilder, Object> map = null;
|
38
|
+ public void msetCacheByString(UfoProductCacheKeyEnum cacheKeyEnum, CachekeyParamsAndValue... keyParams) {
|
|
|
39
|
+ Map<RedisKeyBuilder, Object> map = new HashMap<>();
|
|
|
40
|
+ for (CachekeyParamsAndValue params : keyParams) {
|
|
|
41
|
+ RedisKeyBuilder redisKeyBuilder = getRedisKeyBuilder(cacheKeyEnum, params.getCacheKeyparams());
|
|
|
42
|
+ map.put(redisKeyBuilder, params.getValue());
|
|
|
43
|
+ }
|
|
|
44
|
+
|
39
|
cacheClient.mset(map, cacheKeyEnum.getExpireSecondTime());
|
45
|
cacheClient.mset(map, cacheKeyEnum.getExpireSecondTime());
|
40
|
}
|
46
|
}
|
41
|
|
47
|
|
|
@@ -47,7 +53,7 @@ public class UfoProductCacheService { |
|
@@ -47,7 +53,7 @@ public class UfoProductCacheService { |
47
|
* @param <T>
|
53
|
* @param <T>
|
48
|
* @return
|
54
|
* @return
|
49
|
*/
|
55
|
*/
|
50
|
- public <T> T getCacheByString(UfoProductCacheKeyEnum cacheKeyEnum, Class<T> clazz, String... keyParams) {
|
56
|
+ public <T> T getCacheByString(UfoProductCacheKeyEnum cacheKeyEnum, Class<T> clazz, Object... keyParams) {
|
51
|
RedisKeyBuilder redisKeyBuilder = getRedisKeyBuilder(cacheKeyEnum, keyParams);
|
57
|
RedisKeyBuilder redisKeyBuilder = getRedisKeyBuilder(cacheKeyEnum, keyParams);
|
52
|
return cacheClient.get(redisKeyBuilder, clazz);
|
58
|
return cacheClient.get(redisKeyBuilder, clazz);
|
53
|
}
|
59
|
}
|
|
@@ -64,7 +70,7 @@ public class UfoProductCacheService { |
|
@@ -64,7 +70,7 @@ public class UfoProductCacheService { |
64
|
}
|
70
|
}
|
65
|
|
71
|
|
66
|
|
72
|
|
67
|
- private RedisKeyBuilder getRedisKeyBuilder(UfoProductCacheKeyEnum cacheKeyEnum, String[] keyParams) {
|
73
|
+ private RedisKeyBuilder getRedisKeyBuilder(UfoProductCacheKeyEnum cacheKeyEnum, Object[] keyParams) {
|
68
|
RedisKeyBuilder redisKeyBuilder = RedisKeyBuilder.newInstance();
|
74
|
RedisKeyBuilder redisKeyBuilder = RedisKeyBuilder.newInstance();
|
69
|
redisKeyBuilder.appendFixed(cacheKeyEnum.getCacheKey()).appendVarWithMH(keyParams);
|
75
|
redisKeyBuilder.appendFixed(cacheKeyEnum.getCacheKey()).appendVarWithMH(keyParams);
|
70
|
return redisKeyBuilder;
|
76
|
return redisKeyBuilder;
|