|
|
@@ -1,12 +1,9 @@
|
|
|
package com.coffee.common.cache;
|
|
|
|
|
|
-import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
|
import com.baomidou.mybatisplus.annotation.IEnum;
|
|
|
import com.coffee.common.cache.value.Value;
|
|
|
-import org.redisson.api.RMap;
|
|
|
-import org.redisson.api.RedissonClient;
|
|
|
import org.springframework.cache.Cache;
|
|
|
import org.springframework.cache.CacheManager;
|
|
|
import org.springframework.data.redis.core.BoundHashOperations;
|
|
|
@@ -20,9 +17,9 @@ import java.util.Map;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
public class ClusterConfigStorage implements ConfigStorage {
|
|
|
- private final RMap<String, Object> cacheMap;
|
|
|
- public ClusterConfigStorage(RedissonClient redissonClient,String name){
|
|
|
- cacheMap = redissonClient.getMap(name);
|
|
|
+ private BoundHashOperations boundHashOperations;
|
|
|
+ public ClusterConfigStorage(RedisTemplate redisTemplate,String name){
|
|
|
+ boundHashOperations = redisTemplate.opsForSet().getOperations().boundHashOps(name);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -30,8 +27,7 @@ public class ClusterConfigStorage implements ConfigStorage {
|
|
|
if (StrUtil.isEmpty(key)) {
|
|
|
return null;
|
|
|
}
|
|
|
-// return Value.simple(boundHashOperations.get(key));
|
|
|
- return Value.simple(cacheMap.get(key));
|
|
|
+ return Value.simple(boundHashOperations.get(key));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -47,8 +43,7 @@ public class ClusterConfigStorage implements ConfigStorage {
|
|
|
map.put(k,v);
|
|
|
}
|
|
|
});
|
|
|
-// boundHashOperations.putAll(map);
|
|
|
- cacheMap.putAll(map);
|
|
|
+ boundHashOperations.putAll(map);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@@ -58,55 +53,47 @@ public class ClusterConfigStorage implements ConfigStorage {
|
|
|
return true;
|
|
|
}
|
|
|
if(value==null){
|
|
|
- cacheMap.remove(key);
|
|
|
-// boundHashOperations.delete(key);
|
|
|
+ boundHashOperations.delete(key);
|
|
|
}else {
|
|
|
if(value instanceof IEnum){
|
|
|
value=((IEnum) value).getValue();
|
|
|
}
|
|
|
-// boundHashOperations.put(key,value);
|
|
|
- cacheMap.put(key,value);
|
|
|
+ boundHashOperations.put(key,value);
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Value getAndRemove(String key) {
|
|
|
-// Value value = Value.simple(boundHashOperations.get(key));
|
|
|
-// boundHashOperations.delete(key);
|
|
|
-
|
|
|
- return Value.simple(cacheMap.remove(key));
|
|
|
+ Value value = Value.simple(boundHashOperations.get(key));
|
|
|
+ boundHashOperations.delete(key);
|
|
|
+ return value;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Boolean remove(String key) {
|
|
|
-// boundHashOperations.delete(key);
|
|
|
- cacheMap.remove(key);
|
|
|
+ boundHashOperations.delete(key);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Boolean remove(Collection<String> key) {
|
|
|
-// boundHashOperations.delete(key);
|
|
|
- cacheMap.fastRemove(key.toArray(new String[CollectionUtil.size(key)]));
|
|
|
+ boundHashOperations.delete(key);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Boolean clear() {
|
|
|
-// boundHashOperations.delete(boundHashOperations.keys());
|
|
|
- cacheMap.readAllMap();
|
|
|
+ boundHashOperations.delete(boundHashOperations.keys());
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Map<String, Value> getKeys(Collection<String> keys) {
|
|
|
Map<String, Value> result = new HashMap<>();
|
|
|
- Map<String, Object> map = cacheMap.readAllMap();
|
|
|
-// keys.parallelStream().forEach(key->{
|
|
|
-// result.put(key,getConfig(key));
|
|
|
-// });
|
|
|
- map.forEach((k,v)->result.put(k,Value.simple(v)));
|
|
|
+ keys.parallelStream().forEach(key->{
|
|
|
+ result.put(key,getConfig(key));
|
|
|
+ });
|
|
|
return result;
|
|
|
}
|
|
|
}
|