When a Redis server stores many records, the jedis.keys() command can recycle. Thus, when a task stops, it stops. Instead, you use jedis.hscan() to avoid the problem above.
ScanParams scanParam = new ScanParams(); String cursor = "0"; int i = 0; scanParam.match(prefix + "*"); scanParam.count(50000); // 2000 or 30000 depend on your do { ScanResult<Map.Entry<String, String>> hscan = jedis.hscan(key, cursor, scanParam); // any code here // // // check cursor cursor = hscan.getStringCursor(); } while("0".equals(cursor));
This works well in your case.
source share