...
|
...
|
@@ -2,9 +2,11 @@ package com.yohoufo.product.cache; |
|
|
|
|
|
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
|
|
|
import com.yohoufo.common.cache.CacheClient;
|
|
|
import com.yohoufo.common.cache.CachekeyParamsAndValue;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -21,7 +23,7 @@ public class UfoProductCacheService { |
|
|
* @param value 缓存的值
|
|
|
* @param keyParams 缓存key可变的参数列表 可空
|
|
|
*/
|
|
|
public void setCacheByString(UfoProductCacheKeyEnum cacheKeyEnum, Object value, String... keyParams) {
|
|
|
public void setCacheByString(UfoProductCacheKeyEnum cacheKeyEnum, Object value, Object... keyParams) {
|
|
|
RedisKeyBuilder redisKeyBuilder = getRedisKeyBuilder(cacheKeyEnum, keyParams);
|
|
|
cacheClient.setEx(redisKeyBuilder, value, cacheKeyEnum.getExpireSecondTime());
|
|
|
}
|
...
|
...
|
@@ -33,9 +35,13 @@ public class UfoProductCacheService { |
|
|
* @param value 缓存的值
|
|
|
* @param keyParams 缓存key可变的参数列表 可空
|
|
|
*/
|
|
|
public void msetCacheByString(UfoProductCacheKeyEnum cacheKeyEnum, Object value, String... keyParams) {
|
|
|
RedisKeyBuilder redisKeyBuilder = getRedisKeyBuilder(cacheKeyEnum, keyParams);
|
|
|
Map<RedisKeyBuilder, Object> map = null;
|
|
|
public void msetCacheByString(UfoProductCacheKeyEnum cacheKeyEnum, CachekeyParamsAndValue... keyParams) {
|
|
|
Map<RedisKeyBuilder, Object> map = new HashMap<>();
|
|
|
for (CachekeyParamsAndValue params : keyParams) {
|
|
|
RedisKeyBuilder redisKeyBuilder = getRedisKeyBuilder(cacheKeyEnum, params.getCacheKeyparams());
|
|
|
map.put(redisKeyBuilder, params.getValue());
|
|
|
}
|
|
|
|
|
|
cacheClient.mset(map, cacheKeyEnum.getExpireSecondTime());
|
|
|
}
|
|
|
|
...
|
...
|
@@ -47,7 +53,7 @@ public class UfoProductCacheService { |
|
|
* @param <T>
|
|
|
* @return
|
|
|
*/
|
|
|
public <T> T getCacheByString(UfoProductCacheKeyEnum cacheKeyEnum, Class<T> clazz, String... keyParams) {
|
|
|
public <T> T getCacheByString(UfoProductCacheKeyEnum cacheKeyEnum, Class<T> clazz, Object... keyParams) {
|
|
|
RedisKeyBuilder redisKeyBuilder = getRedisKeyBuilder(cacheKeyEnum, keyParams);
|
|
|
return cacheClient.get(redisKeyBuilder, clazz);
|
|
|
}
|
...
|
...
|
@@ -64,7 +70,7 @@ public class UfoProductCacheService { |
|
|
}
|
|
|
|
|
|
|
|
|
private RedisKeyBuilder getRedisKeyBuilder(UfoProductCacheKeyEnum cacheKeyEnum, String[] keyParams) {
|
|
|
private RedisKeyBuilder getRedisKeyBuilder(UfoProductCacheKeyEnum cacheKeyEnum, Object[] keyParams) {
|
|
|
RedisKeyBuilder redisKeyBuilder = RedisKeyBuilder.newInstance();
|
|
|
redisKeyBuilder.appendFixed(cacheKeyEnum.getCacheKey()).appendVarWithMH(keyParams);
|
|
|
return redisKeyBuilder;
|
...
|
...
|
|