redis中使用scan替换keys的使用

 

Set keys = redisTemplate.keys(Constant.PREFIX_SHIRO_REFRESH_TOKEN + "*")

 替换后:

Set keys = redisTemplate.execute((RedisCallback>) connection -> {
            Set partUers = new HashSet<>();
            // 放在try中自动释放cursor
            try (Cursor cursor = connection.scan(new ScanOptions.ScanOptionsBuilder()
                    .match(Constant.PREFIX_SHIRO_REFRESH_TOKEN + "*").count(50000).build())) {
                while (cursor.hasNext()) {
                    partUers.add(new String(cursor.next()));
                }
            } catch (IOException e) {
                log.error("getTotalUsers cursor close {}", e);
            }
            return partUers;
        });
        

 

你可能感兴趣的:(java后台,springBoot)