redis 通过流批量删除,避免阻塞

 private List<String> getClearRiskKeys(String key){
        List<String> userIdList = new ArrayList<>();
        ScanOptions scanOptions = ScanOptions.scanOptions().count(100).build();
        try(Cursor<Map.Entry<String,String>> cursor = stringRedisTemplate.<String,String>opsForHash().scan(key, scanOptions)) {
            while (cursor.hasNext()){
                Map.Entry<String,String> kv = cursor.next();
                userIdList.add(kv.getKey());
            }
        }catch (IOException e){
            logger.error("每周日定时清理长时间未下单风控用户异常",e);
        }
        return userIdList;
    }

  

posted @ 2021-03-30 20:01  不愿意透露姓名的华  阅读(235)  评论(0)    收藏  举报