1:循环读取:
for (StockBean stockBean:stockBeans) {
long t1=System.currentTimeMillis(); //获取开始时间
String symbol=stockBean.getSymbol();
Map<String, String> map1=new HashMap<>();
JSONObject object=JSONObject.parseObject(redisService.getCacheMap(symbol));
map1.put(symbol,object.getString("price"));
maps.add(map1);
long t2=System.currentTimeMillis(); //获取结束时间
// log.info("获取股票"+symbol+"需要时间:"+(t2-t1)+"ms");
}
耗时:循环读取耗时:5393ms
2:批量读取:
long t1 = System.currentTimeMillis(); //获取开始时间
Collection<Object> collection=new ArrayList<>();
for (StockBean stockBean:stockBeans){
collection.add(stockBean.getSymbol());
}
List<Object> list = redisService.opsForHashGetWithPrices
springboot 整合redis 读取批量hash 取最优时间对比
最新推荐文章于 2024-06-29 11:02:00 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)