@Autowired
private RedisTemplate<String, String> redisTemplate; @Override
public List<String> getCachedList(String key)
{
Long size = getCachedListSize(key);
Long end = size - 1;
return getCachedListByRange(key,0L,end);
} @Override
public Long getCachedListSize(String key)
{
return redisTemplate.opsForList().size(key);
} @Override
public List<String> getCachedListByRange(String key, Long start, Long end)
{
return redisTemplate.opsForList().range(key,start,end);
} @Override
public <T> List<T> getCachedList(List<String> jsons, Class<T> targetClass)
{
if(CollectionUtils.isEmpty(jsons))
{
return Collections.emptyList();
}
return jsons.stream().map(json->JSON.parseObject(json,targetClass)).collect(Collectors.toCollection(LinkedList::new));
} @Override
public <T> List<T> getCachedList(String snapshotKey, String ipAddr, final Predicate<? super T> filter, Class<T> targetClass)
{
List<T> list = getCachedList(snapshotKey,ipAddr, targetClass); if(CollectionUtils.isEmpty(list))
{
return Collections.emptyList();
}
return list.parallelStream().filter(filter).collect(Collectors.toList());
}

hash操作

    @Override
public <T> Map<String,T> getCachedKV(String cachedKey, String hashKey, Long nodeId, Class<T> targetClass)
{
String statusId = String.format("%s:nodeId%d", cachedKey,nodeId); List<Map<String,T>> list = getCachedKV(statusId,targetClass);
if(CollectionUtils.isEmpty(list))
{
return Collections.emptyMap();
}
Optional<Map<String, T>> matched = list.stream().filter(map -> {
return map.keySet().contains(hashKey);
}).findFirst(); if(matched.isPresent()) {
return matched.get();
}
return Collections.emptyMap();
}
@Override
public <T> List<Map<String,T>> getCachedKV(String cachedId, Class<T> targetClass)
{
Map<Object, Object> memCached = redisTemplate.opsForHash().entries(cachedId);
if (MapUtils.isEmpty(memCached)) {
return Collections.emptyList();
}
List<Map<String,T>> list = new LinkedList<Map<String,T>>(); for(Map.Entry<Object,Object> entry:memCached.entrySet())
{
String key = (String)entry.getKey();
String json = (String)entry.getValue();
list.add(Collections.singletonMap(key,JSON.parseObject(json,targetClass)));
}
return list;
} @Override
public <T> T getStatus(String statusKey, String hashKey, Long nodeId, Class<T> targetClass)
{
Map<String, T> result = getCachedKV(statusKey, hashKey, nodeId, targetClass); if(!result.isEmpty())
{
Optional<T> entity = result.values().stream().findFirst();
if(entity.isPresent())
{
return entity.get();
}
} return null;
} @Override
public <T> T getCachedObjectFromList(String cacheId, Class<T> targetClass)
{
List<T> list = new LinkedList<>(); Map<Object, Object> memCached = redisTemplate.opsForHash().entries(cacheId); Optional<String> matched = memCached.values().stream().map(String::valueOf).findFirst();
if(matched.isPresent())
{
String json = matched.get();
return JSON.parseObject(json,targetClass);
}
return null;
} @Override
public List<SnmpNode> getCachedNodes()
{
return getHashValues(CACHED_NODE,SnmpNode.class);
} @Override
public <T> List<T> getHashValues(String cacheId, Class<T> targetClass)
{
List<T> list = new LinkedList<>(); Map<Object, Object> memCached = redisTemplate.opsForHash().entries(cacheId);
if(MapUtils.isEmpty(memCached))
{
return Collections.synchronizedList(Collections.emptyList());
} for (Map.Entry<Object, Object> entry : memCached.entrySet()) {
String key = (String) entry.getKey();
String json = (String) entry.getValue();
T instance = JSON.parseObject(json,targetClass);
log.debug("list@{}查询到的数据,key:{},val:{}",cacheId,key,json);
list.add(instance);
}
return list;
}

最新文章

  1. js复杂对象和简单对象的简单转化
  2. 数据集偏斜 - class skew problem - 以SVM松弛变量为例
  3. Groovy学习笔记(二)
  4. mysql 把文件中的sql语句导入到mysql中
  5. 读书笔记——Windows环境下32位汇编语言程序设计(5)模态对话框
  6. python socket编程详细介绍
  7. J2EE学习中一些值得研究的开源项(转)
  8. MongoDB小记
  9. Uncaught SyntaxError: Unexpected token ILLEGAL【js错误】
  10. 【转】iOS开发工具系列(按功能分)
  11. flexbox布局模式-- 浅谈
  12. .net 破解的几个常用工具
  13. hdoj 1072 Nightmare
  14. nbtstat 查询IP地址对应的计算机名称
  15. springboot+vue前后端分离,nginx代理配置 tomcat 部署war包详细配置
  16. Android 取消标题栏
  17. 打造利器Qt Creator:代码todo工具的使用
  18. 睡前小dp-poj1276-多重背包+二进制优化
  19. 遍历List、Map删除元素
  20. Vim中自动在程序起始处添加版权和作者信息

热门文章

  1. Ubuntu18.04安装破解版MATLAB2018b
  2. Python:面向对象编程2
  3. Easy UI 入门
  4. IIS无法启动解决方案
  5. tensorflow2.0 在pycharm下提示问题
  6. MySQL字符集或字符序
  7. Linux/Ubantu 安装 idea
  8. 1 request模块
  9. SpringCloud之网关 Gateway(五)
  10. Codeforces 1214 F G H 补题记录