java—尝试测试redis缓存方法

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

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

List<Optional<Facility>> cacheFacilities = new ArrayList<>();
        RedisConnection redisConnection = null;
        try {
            LOGGER.info("Making redis connection......");
            redisConnection = redisTemplate.getConnectionFactory().getConnection();
            LOGGER.info("Successfully made redis connection......");
            ScanOptions options = ScanOptions.scanOptions().build();
            Cursor c = redisConnection.scan(options);

            while (c.hasNext()) {
                String facilityKey = new String((byte[]) c.next());
                facilityKey = facilityKey.substring(facilityKey.indexOf("Facility:") + 9);
                cacheFacilities.add(facilityRepository.findById(facilityKey));
            }
        }
        finally {
            redisConnection.close();
            LOGGER.info("Redis connection closed!!");
        }```

I am using RedisTemplate for making the connection. Could someone please help me with this. I want to test these lines of code.

暂无答案!

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

相关问题