使用Cursor<Map.Entry<Object, Object>> cursor = jsonRedisTemplate.opsForHash() .scan(key, ScanOptions.scanOptions().match("123“).build());方法时,使用完cursor 需要关闭,否则将会一致占用连接,最终导致线程池崩溃。需要直接调用cursor.close()。
try (Cursor<Map.Entry<Object, Object>> cursor = jsonRedisTemplate.opsForHash().scan(key)) { if (cursor == null) { return; } while (cursor.hasNext()) { Map.Entry<Object, Object> entry = cursor.next(); String key = String.valueOf(entry.getKey()); } } catch (Exception ex) { log.info(ex.toString()); }