java—尝试测试redis缓存方法

ycl3bljg  于 2021-06-10  发布在  Redis
关注(0)|答案(0)|浏览(280)

我正在尝试测试这个方法。我试着用mockito spy来获取数据,但没有按计划进行。

  1. List<Optional<Facility>> cacheFacilities = new ArrayList<>();
  2. RedisConnection redisConnection = null;
  3. try {
  4. LOGGER.info("Making redis connection......");
  5. redisConnection = redisTemplate.getConnectionFactory().getConnection();
  6. LOGGER.info("Successfully made redis connection......");
  7. ScanOptions options = ScanOptions.scanOptions().build();
  8. Cursor c = redisConnection.scan(options);
  9. while (c.hasNext()) {
  10. String facilityKey = new String((byte[]) c.next());
  11. facilityKey = facilityKey.substring(facilityKey.indexOf("Facility:") + 9);
  12. cacheFacilities.add(facilityRepository.findById(facilityKey));
  13. }
  14. }
  15. finally {
  16. redisConnection.close();
  17. LOGGER.info("Redis connection closed!!");
  18. }```
  19. I am using RedisTemplate for making the connection. Could someone please help me with this. I want to test these lines of code.

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题