TiBaImageService { @Transactional(readOnly = false) public void sychReisToMySql() { long beginTime = System.currentTimeMillis(); List<TieBaImage> tiebaImageList = new ArrayList<>(); Set<String> setTieBaName = redisTemplate.opsForSet().members(TIEBA_NAME_KEY); redisTemplate.execute(new RedisCallback<Object>() { public Object doInRedis(RedisConnection redisConnection) throws DataAccessException { for (String tieBaName : setTieBaName) { byte[] imageKey = getByte(TieBaImageIdMessageListener.TIEBA_CONTENT_IMAGE_KEY + tieBaName); long bime = System.currentTimeMillis(); Map<byte[], byte[]> mapByte = redisConnection.hGetAll(imageKey); log.info(mapByte.size() + "数据，hGetAll耗时：" + (System.currentTimeMillis() - bime) / 1000 + "s"); for (Iterator<byte[]> iter = mapByte.keySet().iterator(); iter.hasNext(); ) { byte[] pageId = iter.next(); byte[] imageUrl = mapByte.get(pageId); if (imageUrl != null) { tiebaImageList.add(new TieBaImage(WebmagicService.getString(pageId), WebmagicService.getString(imageUrl), tieBaName)); } } } return null; } }); log.info("redis循环总耗时：" + (System.currentTimeMillis() - beginTime) / 1000 + "s"); log.info("待同步入库数据大小：" + tiebaImageList.size()); beginTime = System.currentTimeMillis(); threadInsert(tiebaImageList); long endIime = System.currentTimeMillis(); log.info("数据库插入耗时：" + (endIime - beginTime) / 1000 + "s"); }  @Transactional(readOnly = false) void sychReisToMySql();  }
@Test public void sychReisToMySql() throws Exception { tiBaImageService.sychReisToMySql(); }